473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Object Reference Error On Setting sqlCommand connection

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

Jan 6 '06 #1
2 1309
tjonsek,

Dim sql As New SqlClient.SqlCommand

Kerry Moorman
"tj*****@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

Jan 6 '06 #2
Thank you Kerry.
That was a case of staring at something long enough to overlook the
obvious.

Jan 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
7
by: kon george | last post by:
Can somebody assist. I build this code on a dev laptop and copied across the entire code to a Windows 2003 server with 1.1 framework. It is basic ASP.NE T that uses web service for SQL Server...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
17
by: Rodusa | last post by:
I am getting this exception error which is driving me nuts. System.NullReferenceException - Object reference not set to an instance of an object If I comment this line, I don't get any errors:...
0
by: Roman | last post by:
I'm trying to create the form which would allow data entry to the Client table, as well as modification and deletion of existing data rows. For some reason the DataGrid part of functionality stops...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
2
by: Dmension | last post by:
"Dmension" <dfoote@napcosecurity.com> wrote in message news:... > Here is a snippet of my code. At "SDA.SelectCommand.CommandText = "Select > (*) FROM Badge " I get an error message that says...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
4
by: Laura K | last post by:
Hi. I am trying to put a drop down in a repeater. I had this working in dreamweaver but now I am trying to transfer it into VS. I am obviously missing something. I am getting the following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.