T
tjonsek
I've been reading most of the day on how to use datagrids and came up
with code to delete a record. I'm getting an error "Object Reference
not set to an instance of an object" for the line where I set the
command's connection. I really am confused as this same basic code
works throughout my project. I thought perhaps because the event is
bubbling up from the datagrid?
Here's my code. Any insight would help. Thanks.
(cnnGIS has been configured through the designer and works elsewhere
just fine)
Public Sub Edit_Grid(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim sql As SqlClient.SqlCommand
sql.Connection = cnnGIS ******This is the line that produces an
error*********************
cnnGIS.Open()
sql.CommandType = CommandType.Text
If e.CommandName = "removePayout" Then
sql.CommandText = "Delete from tbl02_employee where
emp_key='" & e.Item.Cells(0).Text & "'"
Try
sql.ExecuteNonQuery()
Me.daEmp.Fill(DsEmpPay1)
Me.DataGrid1.DataBind()
Catch ex As Exception
lblFail.Text = "Failed to remove employee from record.
" & Err.Description
lblFail.Visible = True
btnFail.Visible = True
End Try
End If
End Sub
with code to delete a record. I'm getting an error "Object Reference
not set to an instance of an object" for the line where I set the
command's connection. I really am confused as this same basic code
works throughout my project. I thought perhaps because the event is
bubbling up from the datagrid?
Here's my code. Any insight would help. Thanks.
(cnnGIS has been configured through the designer and works elsewhere
just fine)
Public Sub Edit_Grid(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim sql As SqlClient.SqlCommand
sql.Connection = cnnGIS ******This is the line that produces an
error*********************
cnnGIS.Open()
sql.CommandType = CommandType.Text
If e.CommandName = "removePayout" Then
sql.CommandText = "Delete from tbl02_employee where
emp_key='" & e.Item.Cells(0).Text & "'"
Try
sql.ExecuteNonQuery()
Me.daEmp.Fill(DsEmpPay1)
Me.DataGrid1.DataBind()
Catch ex As Exception
lblFail.Text = "Failed to remove employee from record.
" & Err.Description
lblFail.Visible = True
btnFail.Visible = True
End Try
End If
End Sub