Need help understanding GridView and RowUpdating button. I am trying to update a SQL database table using a GridView and the Edit and Update buttons. My issue is that I am confused on how to pull the values from the row edited into my SQL statement.
So far I have the following code for Updating:
I keep getting an 'Object reference not set to an object instance error'. So I assume I am forgetting to do something in my code or I am completely wrong in what I have written. This is the first time I have tried using the Edit and Update buttons.
Any help would greatly be appreciated before I pull all my hair out.
Thanks
So far I have the following code for Updating:
VB.NET:
Protected Sub ResultsView_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles ResultsView.RowUpdating
Dim sUserName As String = ResultsView.SelectedRow.Cells(1).Text
Dim sCorp As String = ResultsView.SelectedRow.Cells(2).Text
Dim sDashIn As String = ResultsView.SelectedRow.Cells(3).Text
Dim sDMO As String = ResultsView.SelectedRow.Cells(4).Text
Dim sSMO As String = ResultsView.SelectedRow.Cells(5).Text
Dim sSMOMF As String = ResultsView.SelectedRow.Cells(6).Text
Dim sMaint As String = ResultsView.SelectedRow.Cells(7).Text
Dim DB As ADODB.Connection
Dim sSQL As String
DB = New ADODB.Connection
DB.Open("DSN=Warehouse", "xyz", "test")
sSQL = "UPDATE sales_users SET corporate = '" & sCorp & "', "
sSQL += "dashin = '" & sDashIn & "', "
sSQL += "dmo = '" & sDMO & "', "
sSQL += "smo = '" & sSMO & "', "
sSQL += "smomf = '" & sSMOMF & "', "
sSQL += "maint = '" & sMaint & "' "
sSQL += "WHERE username = '" & sUserName & "'"
DB.Execute(sSQL)
End Sub
I keep getting an 'Object reference not set to an object instance error'. So I assume I am forgetting to do something in my code or I am completely wrong in what I have written. This is the first time I have tried using the Edit and Update buttons.
Any help would greatly be appreciated before I pull all my hair out.
Thanks