Hi. I'm new to VB.net and am used to working with recordsets (much
easier). I have a datagrid that, when the user double clicks on a row,
I am giving them a chance to delete it. I thought this would be simple
but it's taking me forever. I am getting an error when I try to delete
the record. I can't figure out what I'm doing wrong.
The error is "Object reference not set to an instance of an object".
None of the incredibly overpriced books I have seem to be of any help.
Someone's knowledge would be greatly appreciated.
Private Sub dgProjItems_Dou bleClick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles dgProjItems.Dou bleClick
Dim CurItemID As String
CurItemID = dgProjItems.Ite m(dgProjItems.C urrentRowIndex( ), 0)
Dim strConnectionSt ring As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data
Source=C:\Datab ases\NewEstimat e.mdb;"
Dim cn As New OleDbConnection (strConnectionS tring)
Dim strSQLl As String = "Select * from ProjectsItems Where
ItemID = '" & CurItemID & "'"
Dim objCommand1 As New OleDbCommand(st rSQLl, cn)
Dim da As New OleDbDataAdapte r(objCommand1)
Dim ds As New DataSet
Try
cn.Open()
Dim cb As New OleDb.OleDbComm andBuilder(da)
ds.Tables("Proj ectItems").Rows (0).Delete() 'error here
da.Update(ds, "ProjectIte ms")
Me.dgProjItems. DataSource = ds.Tables("Proj ectItems")
Catch OleDbExceptionE rr As OleDb.OleDbExce ption
MessageBox.Show (OleDbException Err.Message, "Access SQL")
End Try
End Sub 7 3687 tr********@yaho o.com wrote: Hi. I'm new to VB.net and am used to working with recordsets (much easier). I have a datagrid that, when the user double clicks on a row, I am giving them a chance to delete it. I thought this would be simple but it's taking me forever. I am getting an error when I try to delete the record. I can't figure out what I'm doing wrong. The error is "Object reference not set to an instance of an object". None of the incredibly overpriced books I have seem to be of any help. Someone's knowledge would be greatly appreciated.
Private Sub dgProjItems_Dou bleClick(ByVal sender As Object, ByVal e As System.EventArg s) Handles dgProjItems.Dou bleClick Dim CurItemID As String CurItemID = dgProjItems.Ite m(dgProjItems.C urrentRowIndex( ), 0)
Dim strConnectionSt ring As String = _ "Provider=Micro soft.Jet.OLEDB. 4.0;" & _ "Data Source=C:\Datab ases\NewEstimat e.mdb;" Dim cn As New OleDbConnection (strConnectionS tring) Dim strSQLl As String = "Select * from ProjectsItems Where ItemID = '" & CurItemID & "'" Dim objCommand1 As New OleDbCommand(st rSQLl, cn) Dim da As New OleDbDataAdapte r(objCommand1) Dim ds As New DataSet
Try cn.Open()
Dim cb As New OleDb.OleDbComm andBuilder(da)
ds.Tables("Proj ectItems").Rows (0).Delete() 'error here da.Update(ds, "ProjectIte ms")
Me.dgProjItems. DataSource = ds.Tables("Proj ectItems")
Catch OleDbExceptionE rr As OleDb.OleDbExce ption MessageBox.Show (OleDbException Err.Message, "Access SQL") End Try End Sub
"Object reference not set to an instance of an object"
This error means that an object you are trying to do an operation
against does not exist (is nothing). so figure out which object is empty.
dim DT as datatable = ds.Tables("Proj ectItems")
dim DR as datarow = DT.Rows(0)
DR.Delete()
My guess is that your datatable isn't named ProjectItems so that is
returning nothing.
Chris
Your code isn't going to work because on one line you create a new empty
dataset:
Dim ds As New DataSet
And then on another line, you are attempting to delete from this empty
dataset:
ds.Tables("Proj ectItems").Rows (0).Delete() 'error here
You're never calling Fill on your OleDbDataAdapte r to fill this dataset so
that you can delete the row.
"tr********@yah oo.com" wrote: Hi. I'm new to VB.net and am used to working with recordsets (much easier). I have a datagrid that, when the user double clicks on a row, I am giving them a chance to delete it. I thought this would be simple but it's taking me forever. I am getting an error when I try to delete the record. I can't figure out what I'm doing wrong. The error is "Object reference not set to an instance of an object". None of the incredibly overpriced books I have seem to be of any help. Someone's knowledge would be greatly appreciated.
Private Sub dgProjItems_Dou bleClick(ByVal sender As Object, ByVal e As System.EventArg s) Handles dgProjItems.Dou bleClick Dim CurItemID As String CurItemID = dgProjItems.Ite m(dgProjItems.C urrentRowIndex( ), 0)
Dim strConnectionSt ring As String = _ "Provider=Micro soft.Jet.OLEDB. 4.0;" & _ "Data Source=C:\Datab ases\NewEstimat e.mdb;" Dim cn As New OleDbConnection (strConnectionS tring) Dim strSQLl As String = "Select * from ProjectsItems Where ItemID = '" & CurItemID & "'" Dim objCommand1 As New OleDbCommand(st rSQLl, cn) Dim da As New OleDbDataAdapte r(objCommand1) Dim ds As New DataSet
Try cn.Open()
Dim cb As New OleDb.OleDbComm andBuilder(da)
ds.Tables("Proj ectItems").Rows (0).Delete() 'error here da.Update(ds, "ProjectIte ms")
Me.dgProjItems. DataSource = ds.Tables("Proj ectItems")
Catch OleDbExceptionE rr As OleDb.OleDbExce ption MessageBox.Show (OleDbException Err.Message, "Access SQL") End Try End Sub
Thank you both for your quick reply.
Scott........I added the fill method and now get the error "An
unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred
in system.data.dll "
Here's the revised code:
Dim strSQLl As String = "Select * from ProjectItems Where ItemID = '" &
CurItemID & "'"
Dim objCommand1 As New OleDbCommand(st rSQLl, cn)
Dim da As New OleDbDataAdapte r(objCommand1)
Dim ds As New DataSet
da.Fill(ds, "ProjectIte ms")
Try
cn.Open()
Dim cb As New OleDb.OleDbComm andBuilder(da)
ds.Tables("Proj ectItems").Rows (0).Delete()
da.Update(ds, "ProjectIte ms")
Me.dgProjItems. DataSource = ds.Tables("Proj ectItems")
Catch OleDbExceptionE rr As OleDb.OleDbExce ption
MessageBox.Show (OleDbException Err.Message, "Access SQL")
End Try
Chris........Th e table name is correct. Thanks. tr********@yaho o.com wrote: Thank you both for your quick reply. Scott........I added the fill method and now get the error "An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in system.data.dll "
Here's the revised code:
Dim strSQLl As String = "Select * from ProjectItems Where ItemID = '" & CurItemID & "'" Dim objCommand1 As New OleDbCommand(st rSQLl, cn) Dim da As New OleDbDataAdapte r(objCommand1) Dim ds As New DataSet da.Fill(ds, "ProjectIte ms") Try cn.Open()
Dim cb As New OleDb.OleDbComm andBuilder(da)
ds.Tables("Proj ectItems").Rows (0).Delete()
da.Update(ds, "ProjectIte ms")
Me.dgProjItems. DataSource = ds.Tables("Proj ectItems")
Catch OleDbExceptionE rr As OleDb.OleDbExce ption MessageBox.Show (OleDbException Err.Message, "Access SQL") End Try
Chris........Th e table name is correct. Thanks.
what does oledbexceptione rr.message say? It will give more detail about
what the error is.
Chris
I ran through all the code. That's the only error I get.
Travlintom,
At least do you consequently have to close something when you open
something. Closing and opening is in fact not needed for a dataadapter
(however better when you use more tables), because the dataadapter does that
generic for you.
Your block could be this both for the Fill and the Update
Try
open connection
Try
fill or update
Catch error
'do action for the Try or Update
End Try
Catch error
'do action for the Open
Finally
Close connection
End Try
As I wrote, you can not use the open. In Net 2.0 you can than use as well
"using".
I hope this helps,
Cor
Thanks all. I found the problem. It was actually the SQL statement was
looking for a string when It should have been an integer. I made the
change and it works fine. Thanks for all your help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter Gomis |
last post by:
I have encountered a situation where I am unable to remove
a .NET assembly from the GAC. The message I receive
is "Assembly 'assemblyname' could not be uninstalled
because it is required by other applications." Although I
have seen this before when trying to remove .NET
assemblies that have been installed via an MSI package, I
now get this message while trying to remove any assembly
I've added to the GAC. Using gacutil does not work...
|
by: Barbara |
last post by:
Hi,
I have an sql database that has the primary key set to three fields,
but has not been set as unique(I didn't create the table).
I have 1 record that has 2 duplicates and I am unable to delete the
duplicate entries.
If I try to delete any of the three records(they are identical) I get
the message 'key column is insufficient or incorrect. Too many rows
were affected by update'.
I am trying to do this within Enterprise Mgr.
Any...
|
by: MAF |
last post by:
Does anyone know why in 2005 I might be getting this error everytime I try
and recompile?
Error 226 Unable to copy file "obj\Debug\myfile.dll" to
"bin\Debug\myfile.dll". The process cannot access the file
'bin\Debug\myfile.dll' because it is being used by another process. myfile
|
by: bazzer |
last post by:
hey,
im trying to access a microsoft access database from an ASP.NET web
application in visual basic 2003.NET. i get the following error when i
try running it:
Server Error in '/CinemaBookingSystem' Application.
--------------------------------------------------------------------------------
ERROR General error
Unable to open registry key 'Temporary (volatile) Jet DSN for process
|
by: Sailor1877 via AccessMonster.com |
last post by:
I've been reading all the threads about problems with LDB files but my
specific problem doesn't seem to be addressed. I have a back end database on
a server that I'm unable to run Compact and Repair on because the LDB file is
still present. It tells me it is being used by a user "Admin" on my machine
(a fact that is echoed when I open the LDB file in Notepad.) Unfortunately
there is no username "Admin" on the network.
When I try to...
| |
by: Wannabe |
last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page reloads except the row I am
trying to delete is still there. I believe it is something really easy, but I
cannot see it. The stored procedue works when run in QA. Can someone tell me
what I am doing wrong/missing that is keeping the delete command from working
in the gridview? Thank you.
I am trying to delete a row out of...
|
by: Buddy Home |
last post by:
Hello,
I'm trying to upload a file programatically and occasionally I get the
following error message.
Unable to write data to the transport connection: An established connection
was aborted by the software in your host machine.
Stack Trace
at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
|
by: Buddy Home |
last post by:
Hello,
I'm trying to upload a file programatically and occasionally I get the
following error message.
Unable to write data to the transport connection: An established connection
was aborted by the software in your host machine.
Stack Trace
at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
|
by: Markw |
last post by:
Hi folks I think I've got a variable problem but not 100% sure.
Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to modify it for use in my own database. It almost works for me LOL.
contact.php returns my dive buddies first and last name and gives me the option to either Edit or Delete them. Currently the delete option is not active.
When I choose to edit...
|
by: maheswaran |
last post by:
Hi,
i have issue in FTP , i have tried with .net and also c#
Note the following scenario:
1. Upload the file to FTP >than 60 MB.
2. At the time of Uploading, unplug the LAN cable (or) In system tray Right click on Local Area connection and select "Disable".
|
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,...
| |
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...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |