Reputation: 31
I wanted to update a column in my table, i have written the code it runs fine without any error also it displays the confirmation dialog box but the table is not updated whats wrong with the code.
Dim sqlConn As New SqlClient.SqlConnection
sqlConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\housingsociety.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Try
sqlConn.Open()
Catch sqlError As Exception
MsgBox(sqlError.Message, 0, "Connection Error!")
End Try
Dim sqlComm As New SqlClient.SqlCommand
sqlComm.Connection = sqlConn
sqlComm.CommandText = "update committe_member set name = '@name' where name = 'member1'"
Dim paramString As New SqlClient.SqlParameter("@name", SqlDbType.VarChar, 50)
paramString.Direction = ParameterDirection.Input
sqlComm.Parameters.Add(paramString)
paramString.Value = TextBox1.Text
sqlComm.ExecuteNonQuery()
MsgBox("Record Sucessfully Altered", 0, "Confirmation!")
sqlConn.Close()
Upvotes: 0
Views: 2126
Reputation: 499312
You do not need to quote the parameter in your SQL string.
Try the following:
sqlComm.CommandText = "update committe_member set name = @name where name = 'member1'"
I would also set the parameter value before adding it to the parameters collection:
paramString.Value = TextBox1.Text
sqlComm.Parameters.Add(paramString)
Upvotes: 1