Sql query in ASP.NET
I am using the following query to update record in asp.net, what's wrong with it?
Dim updateSqlString As String = "UPDATE Subscriber_Communication SET([[marketing_rec_id]=?, [Currently_own]=?,[Purchase_date]=?, [Interested_in_owning]=?, [Product_of_interest]=?," & _
"[Time_frame_to_own]=?, [Referred_by]=?, [Campaign_Code]=?,[Last_Update]=?, [record_created_on]=?, [Comments]=?, [Comment_Date]=?, [Community_id]=?," & _
"[Certification]=?, [subscriber_Type]=?, [unsubscribe_comment]=?" & _
"WHERE [Communication_id]=" & Communication_id
Using conn As New SqlConnection(ConnString)
Using cmd As New SqlCommand(insertSqlString, conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("marketing_rec_id", marketing_rec_id)
cmd.Parameters.AddWithValue("Currently_own", Currently_own)
cmd.Parameters.AddWithValue("Purchase_date", Purchase_date)
cmd.Parameters.AddWithValue("Interested_in_owning", Interested_in_owning)
cmd.Parameters.AddWithValue("Product_of_interest", Product_of_interest)
cmd.Parameters.AddWithValue("Time_frame_to_own", Time_frame_to_own)
cmd.Parameters.AddWithValue("Referred_by", Referred_by)
cmd.Parameters.AddWithValue("Campaign_Code", Campaign_Code)
cmd.Parameters.AddWithValue("Last_Update", Last_Update)
cmd.Parameters.AddWithValue("record_created_on", record_created_on)
cmd.Parameters.AddWithVal开发者_Go百科ue("Comments", Comments)
cmd.Parameters.AddWithValue("Comment_Date", Comment_Date)
cmd.Parameters.AddWithValue("Community_id", Community_id)
cmd.Parameters.AddWithValue("Certification", Certification)
cmd.Parameters.AddWithValue("subscriber_Type", subscriber_Type)
cmd.Parameters.AddWithValue("unsubscribe_comment", unsubscribe_comment)
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
I believe you want:
Dim updateSqlString As String =
"UPDATE Subscriber_Communication SET [marketing_rec_id]=@marketing_rec_id, [Currently_own]=@Currently_own, ..." etc
You have the string variable as
updateSqlString
while you are using
insertSqlString
to update the database .
精彩评论