|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Object Reference Error On Setting sqlCommand connectionwith 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 tjonsek,
Dim sql As New SqlClient.SqlCommand Kerry Moorman Show quoteHide quote "tjon***@phenom-biz.com" wrote: > 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 > > Thank you Kerry.
That was a case of staring at something long enough to overlook the obvious.
Armin - Start sound problem revived in new thread
Use of delegate SetWindowsHookEx and VB.NET 2005 A Framework for Datadriven Forms for VB Dot Net XML Comments File Generated Simple Example of How to Implement SerialPort Class Byte Array, Datagrid Paging, Filtering and Sorting Db Interaction spped issue with upgraded code from vb6 to vb.net Add a line break in label.text |
|||||||||||||||||||||||