473,811 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
DataGridCommand EventArgs)
Dim sql As SqlClient.SqlCo mmand

sql.Connection = cnnGIS ******This is the line that produces an
error********** ***********
cnnGIS.Open()

sql.CommandType = CommandType.Tex t
If e.CommandName = "removePayo ut" Then
sql.CommandText = "Delete from tbl02_employee where
emp_key='" & e.Item.Cells(0) .Text & "'"
Try
sql.ExecuteNonQ uery()
Me.daEmp.Fill(D sEmpPay1)
Me.DataGrid1.Da taBind()
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 1324
tjonsek,

Dim sql As New SqlClient.SqlCo mmand

Kerry Moorman
"tj*****@ph enom-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
DataGridCommand EventArgs)
Dim sql As SqlClient.SqlCo mmand

sql.Connection = cnnGIS ******This is the line that produces an
error********** ***********
cnnGIS.Open()

sql.CommandType = CommandType.Tex t
If e.CommandName = "removePayo ut" Then
sql.CommandText = "Delete from tbl02_employee where
emp_key='" & e.Item.Cells(0) .Text & "'"
Try
sql.ExecuteNonQ uery()
Me.daEmp.Fill(D sEmpPay1)
Me.DataGrid1.Da taBind()
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
10551
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 Error in '/Cr_Dataset' Application. ----------------------------------------------------------- ---------------------
7
597
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 2000 DB access. The code works fine on my dev laptop, just not on the non dev machine. Here is the full error page:
0
9784
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" AutoPostBackOnNodeMove="false" DragAndDropEnabled="true" NodeEditingEnabled="False" KeyboardEnabled="true" CssClass="TreeView" NodeCssClass="TreeNode" SelectedNodeCssClass="SelectedTreeNode" HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
17
9696
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: string Total_Dollar_Amount = GetTotal(sql,"test"); namespace SalesReport
0
2134
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 working when I include data entry fields to the form: I click on Delete or Edit inside of DataGrid and get this error: "Error: Object doesn't support this property or method" If I remove data entry fields from the form - DataGrid allows to...
3
2443
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 object :(((( Anyone pls help me to solve this problem!!! thanks in advance,
2
1085
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 "Additional information: > Object reference not set to an instance of an object" > > Any help would be appreciated.. > > > > Private Sub btnfill_Click(ByVal sender As System.Object, ByVal e As
7
1574
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 Integer = 0 To LinkResults.Length - 1 With MyCurrentClass.SqlCmd_Insert_LinkVB .CommandType = System.Data.CommandType.StoredProcedure
4
491
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 error. "Object reference not set to an instance of an object" THe error is referring to the following line which is located in the function below.
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.