473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't update an Access database

Hi all,

This is my first attempt to update an access database in VB.Net 2005. It
goes broadly as follows (I have condensed it):

Dim MyConnection As New Data.OleDb.OleD bConnection
MyConnection.Co nnectionString = ("Provider=Micr osoft.Jet.OLEDB .4.0;
Data Source=c:\books .mdb")
Dim Myadaptor As OleDb.OleDbData Adapter
Myadaptor = New OleDb.OleDbData Adapter("select * from stockitems",
MyConnection)
Dim MyDataSet As New DataSet
MyConnection.Op en()
Myadaptor.Fill( MyDataSet)
Dim newRow As DataRow = MyDataSet.Table s(0).NewRow
newRow("code") = "New Code"
MyDataSet.Table s(0).Rows.Add(n ewRow)
Myadaptor.Updat e(MyDataSet)
MyConnection.Cl ose()

I have tried a few ways to do this but I always get an error:
"Update requires a valid InsertCommand when passed DataRow collection with
new rows."

Any ideas? Any help gratefully received.

Mark
Feb 17 '07 #1
3 9313

"Mrk Blackall" <Mrk Bl******@discus sions.microsoft .comwrote in message
news:37******** *************** ***********@mic rosoft.com...
Hi all,

This is my first attempt to update an access database in VB.Net 2005. It
goes broadly as follows (I have condensed it):

Dim MyConnection As New Data.OleDb.OleD bConnection
MyConnection.Co nnectionString = ("Provider=Micr osoft.Jet.OLEDB .4.0;
Data Source=c:\books .mdb")
Dim Myadaptor As OleDb.OleDbData Adapter
Myadaptor = New OleDb.OleDbData Adapter("select * from stockitems",
MyConnection)
Dim MyDataSet As New DataSet
MyConnection.Op en()
Myadaptor.Fill( MyDataSet)
Dim newRow As DataRow = MyDataSet.Table s(0).NewRow
newRow("code") = "New Code"
MyDataSet.Table s(0).Rows.Add(n ewRow)
Myadaptor.Updat e(MyDataSet)
MyConnection.Cl ose()

I have tried a few ways to do this but I always get an error:
"Update requires a valid InsertCommand when passed DataRow collection with
new rows."

Any ideas? Any help gratefully received.

Mark

Couldn't you use a SqlCommand (System.Data.Sq lCommand?) and just execute an
INSERT INTO or UPDATE query?
Failing that, look into the properties of your DataSet and ensure you've
opened it for writing as well.
I'd suggest exact code, but I'm only just starting to get used to .NET, and
all the data projects I'm working on, I'm either pulling data from a
webservice, or a SQL2000 database.
I'd hazard a guess that there may be a 3rd option in the OleDbDataAdapte r
constructor that would specify whether you're opening the databse for
reading only(adForwardO nly) or for writing back to it as well.
Also check the file permissions and make sure that you can actually write to
the database?

Hope some of this helps.

--Paul Evans CCNA
SHL Computing

Feb 17 '07 #2
ADO.net is unnecessarily complex

use a command, dipshit


On Feb 16, 4:11 pm, Mrk Blackall <Mrk
Black...@discus sions.microsoft .comwrote:
Hi all,

This is my first attempt to update an access database in VB.Net 2005. It
goes broadly as follows (I have condensed it):

Dim MyConnection As New Data.OleDb.OleD bConnection
MyConnection.Co nnectionString = ("Provider=Micr osoft.Jet.OLEDB .4.0;
Data Source=c:\books .mdb")
Dim Myadaptor As OleDb.OleDbData Adapter
Myadaptor = New OleDb.OleDbData Adapter("select * from stockitems",
MyConnection)
Dim MyDataSet As New DataSet
MyConnection.Op en()
Myadaptor.Fill( MyDataSet)
Dim newRow As DataRow = MyDataSet.Table s(0).NewRow
newRow("code") = "New Code"
MyDataSet.Table s(0).Rows.Add(n ewRow)
Myadaptor.Updat e(MyDataSet)
MyConnection.Cl ose()

I have tried a few ways to do this but I always get an error:
"Update requires a valid InsertCommand when passed DataRow collection with
new rows."

Any ideas? Any help gratefully received.

Mark

Feb 17 '07 #3
You need the OleDBCommandBui lder that will automatically the insert, delete
and update commands.

Here is an example of updating using the commandbuilder from VS 2005 Help

Public Shared Function UpdateRows(conn ectionString As String, _
queryString As String, tableName As String) As DataSet

Dim dataSet As DataSet = New DataSet

Using connection As New OleDbConnection (connectionStri ng)
Dim adapter As New OleDbDataAdapte r()
adapter.SelectC ommand = New OleDbCommand(qu eryString, connection)
Dim cb As OleDbCommandBui lder = New OleDbCommandBui lder(adapter)

connection.Open ()

adapter.Fill(da taSet, tableName)

' Code to modify data in DataSet here

' Without the OleDbCommandBui lder this line would fail.
adapter.Update( dataSet, tableName)
End Using

Return dataSet
End Function
"Mrk Blackall" <Mrk Bl******@discus sions.microsoft .comwrote in message
news:37******** *************** ***********@mic rosoft.com...
Hi all,

This is my first attempt to update an access database in VB.Net 2005. It
goes broadly as follows (I have condensed it):

Dim MyConnection As New Data.OleDb.OleD bConnection
MyConnection.Co nnectionString = ("Provider=Micr osoft.Jet.OLEDB .4.0;
Data Source=c:\books .mdb")
Dim Myadaptor As OleDb.OleDbData Adapter
Myadaptor = New OleDb.OleDbData Adapter("select * from stockitems",
MyConnection)
Dim MyDataSet As New DataSet
MyConnection.Op en()
Myadaptor.Fill( MyDataSet)
Dim newRow As DataRow = MyDataSet.Table s(0).NewRow
newRow("code") = "New Code"
MyDataSet.Table s(0).Rows.Add(n ewRow)
Myadaptor.Updat e(MyDataSet)
MyConnection.Cl ose()

I have tried a few ways to do this but I always get an error:
"Update requires a valid InsertCommand when passed DataRow collection with
new rows."

Any ideas? Any help gratefully received.

Mark


Feb 17 '07 #4

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

Similar topics

12
22930
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL Server database that we have. Question follows: The following SQL statement, used in VBScript,
4
2965
by: Kathleen Turner | last post by:
I have an Excel file that has list of serial numbers followed by a 4 digit code. I have an Access database that has the serial numbers but the field for the 4 digit code is either blank, has the 4 digit code, or contains 4 X's. What I would like to do is go through each record in Access, check the serial number and then compare that serial number with the one in the Excel spreadsheet. If the serial number in Access has a NULL value or...
3
3045
by: intl04 | last post by:
I was told by an instructor of Oracle SQL that an MS Access database cannot be used to have several people enter records at about the same time, that the database will "freeze up" as a result - meaning, it'll lock out everyone else until the first person who got to the database (via a Web application, for example) is done updating his or her record. He was saying that only one update can be done at a time to an Access database. However,...
2
1804
by: pisaac | last post by:
I am considering purchasing Visual Basic .net 2003 Standard Editon to do some development work with Web Forms and I need to know whether this edit will allow me to update an Access database (mdb) file. I already have a database which is updated through an Access front-end, I want to update the database through web forms, is this possible? what are the benefits of going for the Professional Verion of Visual Studio instead? Cheers,
3
3442
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
4
2307
by: George | last post by:
Hi all, I am having trouble with updating my data in an Access database. here is my code: Imports System.Data.OleDb Dim AppPath As String = Mid(Application.ExecutablePath, 1, Len(Application.ExecutablePath) - 14)
2
2322
by: Scotty | last post by:
I get stuck to write an update, insert and delete command, i am looking for some help to start Whats the best way to update 2 tables toe the database (Access) below my code used to load my data.(2 tables) Do someone has a good sample code to help me? Many thanks in advance, Marc.
2
1888
by: DuncanIdaho | last post by:
Hi Apologies if this is similar to a (very) recent post. I was wondering if it is possible to execute an update query that contains a select statement on an MS access 2000 database. I have included a detaled example at the bottom of this post I have the following update query that works as I expect it to on a MySQL database
3
3952
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
7
2886
by: emajka21 | last post by:
I have been working on creating a HR database. Everything is working fine there but now they want a training database. I basically need a few fields from the employee table and I need the full department table. I also need the position titles table along with 1 additional field. I was able to export everything fine to the new database. Is there a way to update the training database when data is updated in the HR database. I figured out...
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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
8639
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...
0
7386
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, 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...
1
2771
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
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
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.