I have a datagrid that is suppose to update information in a sql database, but whenever I click the update button, I get the error below. The only two fields the user is allowed to update is the event and date field. Could someone help me. Thank you in advance.
I get the following error when I run the program.
Procedure 'update_tblevent' expects parameter '@event_3', which was not supplied.
Source Error:
Line 164: connEvent.Open()
Line 165: myCommand.ExecuteNonQuery()
Line 166: connEvent.Close()
Line 167: masterDataGrid.EditItemIndex = -1
My code
Dim eventid As Integer
Dim username As String
Dim strevent As String
Dim _event As TextBox = DirectCast(e.Item.FindControl("Textbox2"), TextBox)
Dim strdate As String
Dim _date As TextBox = DirectCast(e.Item.FindControl("Textbox1"), TextBox)
Dim myCommand As New SqlCommand("update_tblevent", connEvent)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add(New SqlParameter("@event_3", Data.SqlDbType.VarChar, 50))
myCommand.Parameters("@event_3").Value = strevent
myCommand.Parameters.Add(New SqlParameter("@date_4", Data.SqlDbType.DateTime))
myCommand.Parameters("@date_4").Value = strdate
connEvent.Open()
myCommand.ExecuteNonQuery()
connEvent.Close()
masterDataGrid.EditItemIndex = -1
BindGrid()
I get the following error when I run the program.
Procedure 'update_tblevent' expects parameter '@event_3', which was not supplied.
Source Error:
Line 164: connEvent.Open()
Line 165: myCommand.ExecuteNonQuery()
Line 166: connEvent.Close()
Line 167: masterDataGrid.EditItemIndex = -1
My code
Dim eventid As Integer
Dim username As String
Dim strevent As String
Dim _event As TextBox = DirectCast(e.Item.FindControl("Textbox2"), TextBox)
Dim strdate As String
Dim _date As TextBox = DirectCast(e.Item.FindControl("Textbox1"), TextBox)
Dim myCommand As New SqlCommand("update_tblevent", connEvent)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add(New SqlParameter("@event_3", Data.SqlDbType.VarChar, 50))
myCommand.Parameters("@event_3").Value = strevent
myCommand.Parameters.Add(New SqlParameter("@date_4", Data.SqlDbType.DateTime))
myCommand.Parameters("@date_4").Value = strdate
connEvent.Open()
myCommand.ExecuteNonQuery()
connEvent.Close()
masterDataGrid.EditItemIndex = -1
BindGrid()