Hi
I am trying to update more than 1 field in an Access table. I am developing a windows application using an Access database in vb.net.
This is the code that i have for my Update button, which works fine if i want to update the field 'CategoryName' however when i add in the 'Description' field into the sql update statement it doesnt work at all....
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
'open(connection)
con.Open()
cmd.Connection = con
Try
cmd.CommandText = "UPDATE LK_Categories SET CategoryName = mCategoryName, Description = mDescription WHERE PK_CategoryID = mCatID"
Dim param As New OleDb.OleDbParameter
Dim param2 As New OleDb.OleDbParameter
Dim param3 As New OleDb.OleDbParameter
'add content txtProdName as parameter
param.ParameterName = "mCategoryName"
param.Value = CategoryNameTextBox.Text()
cmd.Parameters.Add(param)
param2.ParameterName = "mCatID"
param2.Value = PK_CategoryIDTextBox.Text
cmd.Parameters.Add(param2)
Try
param3.ParameterName = "mDescription"
param3.Value = DescriptionTextBox.Text()
cmd.Parameters.Add(param3)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cmd.ExecuteNonQuery()
MessageBox.Show("customer data successfully updated")
Catch ex As Exception
MessageBox.Show("cust data not updated because " _
& ex.Message)
Finally
'close connection if it is open
If (con.State = ConnectionState.Open) Then
con.Close()
End If
End Try
con.Close()
End Sub