473,408 Members | 2,813 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,408 software developers and data experts.

ADO Update Problem

Hi,

We have a process management system in VB .NET. It usually used text
files, but I'm trying to switch to using access database files and
ADO.

I made a form with a datagrid and a few buttons.

I define the variables for this program as follows:

Imports System.Data.OleDb

Private dbConnRoutine As OleDbConnection = Nothing
Private dbAdapterRoutine As OleDbDataAdapter = Nothing
Private dbDataSetRoutine As DataSet = Nothing
Private dbBuilderRoutine As OleDbCommandBuilder = Nothing

When they press the LOAD button, the following is executed:

Dim connString As String
Dim sql As String
connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" + FileName
dbConnRoutine = New OleDbConnection(connString)

sql = "SELECT * FROM rtnmain"
Dim objCommand As New OleDbCommand(sql, dbConnRoutine)

dbAdapterRoutine = New OleDbDataAdapter(objCommand)
dbAdapterRoutine.TableMappings.Add("Table", "rtnmain")
dbBuilderRoutine = New
OleDbCommandBuilder(dbAdapterRoutine)

dbDataSetRoutine = New DataSet("rtnmain")

dbAdapterRoutine.Fill(dbDataSetRoutine, "rtnmain")
gridRoutine.DataSource =
dbDataSetRoutine.Tables("rtnmain")
gridRoutine.SetDataBinding(dbDataSetRoutine,
"rtnmain")
At which point, the data is loaded. No problems there.

Then, I'll add a row to the datagrid. I press the UPDATE button. The
following code is executed:

dbBuilderRoutine.GetUpdateCommand()
dbAdapterRoutine.Update(dbDataSetRoutine)

The result is an error.

An unhandled exception of type 'System.NullReferenceException'
occurred in system.data.dll

Additional information: Object reference not set to an instance
of an object.

Every example I've checked follows this process. Can anyone point out
what I'm doing wrong, or perhaps an alternative way of updating the
table?

Another question:: do I have to re-fill the dataset before trying to
update?

Thanks!
Tom Junior
Dec 16 '07 #1
2 1325
Hi,

I don't see real errors however not needed in your code is
- the setting to nothing,
- dbBuilderRoutine.GetUpdateCommand()
(The latter can be the reason of your error, I have never used that.)

Cor
"TBass" <tb*@automateddesign.comschreef in bericht
news:f3**********************************@e23g2000 prf.googlegroups.com...
Hi,

We have a process management system in VB .NET. It usually used text
files, but I'm trying to switch to using access database files and
ADO.

I made a form with a datagrid and a few buttons.

I define the variables for this program as follows:

Imports System.Data.OleDb

Private dbConnRoutine As OleDbConnection = Nothing
Private dbAdapterRoutine As OleDbDataAdapter = Nothing
Private dbDataSetRoutine As DataSet = Nothing
Private dbBuilderRoutine As OleDbCommandBuilder = Nothing

When they press the LOAD button, the following is executed:

Dim connString As String
Dim sql As String
connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" + FileName
dbConnRoutine = New OleDbConnection(connString)

sql = "SELECT * FROM rtnmain"
Dim objCommand As New OleDbCommand(sql, dbConnRoutine)

dbAdapterRoutine = New OleDbDataAdapter(objCommand)
dbAdapterRoutine.TableMappings.Add("Table", "rtnmain")
dbBuilderRoutine = New
OleDbCommandBuilder(dbAdapterRoutine)

dbDataSetRoutine = New DataSet("rtnmain")

dbAdapterRoutine.Fill(dbDataSetRoutine, "rtnmain")
gridRoutine.DataSource =
dbDataSetRoutine.Tables("rtnmain")
gridRoutine.SetDataBinding(dbDataSetRoutine,
"rtnmain")
At which point, the data is loaded. No problems there.

Then, I'll add a row to the datagrid. I press the UPDATE button. The
following code is executed:

dbBuilderRoutine.GetUpdateCommand()
dbAdapterRoutine.Update(dbDataSetRoutine)

The result is an error.

An unhandled exception of type 'System.NullReferenceException'
occurred in system.data.dll

Additional information: Object reference not set to an instance
of an object.

Every example I've checked follows this process. Can anyone point out
what I'm doing wrong, or perhaps an alternative way of updating the
table?

Another question:: do I have to re-fill the dataset before trying to
update?

Thanks!
Tom Junior
Dec 17 '07 #2
On Dec 17, 12:21 am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Hi,

I don't see real errors however not needed in your code is
- the setting to nothing,
- dbBuilderRoutine.GetUpdateCommand()
(The latter can be the reason of your error, I have never used that.)

Cor

"TBass" <t...@automateddesign.comschreef in berichtnews:f3**********************************@e 23g2000prf.googlegroups.com...
Hi,
We have a process management system in VB .NET. It usually used text
files, but I'm trying to switch to using access database files and
ADO.
I made a form with a datagrid and a few buttons.
I define the variables for this program as follows:
Imports System.Data.OleDb
Private dbConnRoutine As OleDbConnection = Nothing
Private dbAdapterRoutine As OleDbDataAdapter = Nothing
Private dbDataSetRoutine As DataSet = Nothing
Private dbBuilderRoutine As OleDbCommandBuilder = Nothing
When they press the LOAD button, the following is executed:
Dim connString As String
Dim sql As String
connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" + FileName
dbConnRoutine = New OleDbConnection(connString)
sql = "SELECT * FROM rtnmain"
Dim objCommand As New OleDbCommand(sql, dbConnRoutine)
dbAdapterRoutine = New OleDbDataAdapter(objCommand)
dbAdapterRoutine.TableMappings.Add("Table", "rtnmain")
dbBuilderRoutine = New
OleDbCommandBuilder(dbAdapterRoutine)
dbDataSetRoutine = New DataSet("rtnmain")
dbAdapterRoutine.Fill(dbDataSetRoutine, "rtnmain")
gridRoutine.DataSource =
dbDataSetRoutine.Tables("rtnmain")
gridRoutine.SetDataBinding(dbDataSetRoutine,
"rtnmain")
At which point, the data is loaded. No problems there.
Then, I'll add a row to the datagrid. I press the UPDATE button. The
following code is executed:
dbBuilderRoutine.GetUpdateCommand()
dbAdapterRoutine.Update(dbDataSetRoutine)
The result is an error.
An unhandled exception of type 'System.NullReferenceException'
occurred in system.data.dll
Additional information: Object reference not set to an instance
of an object.
Every example I've checked follows this process. Can anyone point out
what I'm doing wrong, or perhaps an alternative way of updating the
table?
Another question:: do I have to re-fill the dataset before trying to
update?
Thanks!
Tom Junior- Hide quoted text -

- Show quoted text -
Neither of those changes solved the problem. In the end, I had to go
with a rather complicated solution where I wrote a seperate class to
deal with the database interaction, and I set the datagrid to read
only, using buttons and forms for adding/editing rows. That has worked
flawlessly.

Thanks for the feedback.
T
Dec 17 '07 #3

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

Similar topics

6
by: al | last post by:
Greetings, In the customers table in Northwind db, one can update PK (customerid) and all other fields in the same table. My question is how can you do this in the udpate stat. That is, if one...
1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
13
by: abdoly | last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update that is the code private void DataGrid1_UpdateCommand(object source,...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
5
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I...
11
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...
0
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...
0
agi2029
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,...
0
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...

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.