Object Reference Error On Setting sqlCommand connection

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
 
T

tjonsek

Thank you Kerry.
That was a case of staring at something long enough to overlook the
obvious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top