473,831 Members | 2,288 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem updating dataset

I don't understand how I update the table underlying the dataseet
Heres what I have at the moment. In this simple example, it works fine until
I try
adapSimple.Upda te(dsSimple, "Customers" )

What should I be doing instead?
Thanks
Diarmuid

Dim stSQL As String = "SELECT * FROM Customers"

Dim adapSimple As New OleDbDataAdapte r(stSQL, conCONNECT)

Dim dsSimple As New Data.DataSet

Dim rowSimple As Data.DataRow

Try

adapSimple.Fill (dsSimple)

For Each rowSimple In dsSimple.Tables (0).Rows

rowSimple("Cust omerName") &= " X"

Next

adapSimple.Upda te(dsSimple, "Customers" )

Catch ex As Exception

MsgBox(ex.ToStr ing)

Finally

dsSimple.Dispos e()

adapSimple.Disp ose()

End Try
Nov 21 '05 #1
11 1812
Diarmuid,

Changed in this message so watch typos.

\\\\
dim conConnect as new OleDbConnection (connectionsStr ing)
Dim stSQL As String = "SELECT * FROM Customers"
Dim adapSimple As New OleDbDataAdapte r(stSQL, conCONNECT)
Dim dsSimple As New Data.DataSet
Try
adapSimple.Fill (dsSimple)
Catch ex As exception
End Try
For Each rowSimple as DataRow In dsSimple.Tables (0).Rows
rowSimple("Cust omerName") &= " X"
Next
dim cmbSimple as new OleDBCommandBui lder(adapSimple )
Try
adapSimple.Upda te(dsSimple, "Customers" )
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
///

I hope this helps,

Cor
Nov 21 '05 #2
In addition to Cor's reponse, please always include the exact error message
in your posts, instead of just saying that there is a problem. That really
just makes it more work for the people trying to help you.

"Diarmuid" <di******@deads pam.com> wrote in message
news:ey******** ******@TK2MSFTN GP15.phx.gbl...
I don't understand how I update the table underlying the dataseet
Heres what I have at the moment. In this simple example, it works fine
until I try
adapSimple.Upda te(dsSimple, "Customers" )

What should I be doing instead?
Thanks
Diarmuid

Dim stSQL As String = "SELECT * FROM Customers"

Dim adapSimple As New OleDbDataAdapte r(stSQL, conCONNECT)

Dim dsSimple As New Data.DataSet

Dim rowSimple As Data.DataRow

Try

adapSimple.Fill (dsSimple)

For Each rowSimple In dsSimple.Tables (0).Rows

rowSimple("Cust omerName") &= " X"

Next

adapSimple.Upda te(dsSimple, "Customers" )

Catch ex As Exception

MsgBox(ex.ToStr ing)

Finally

dsSimple.Dispos e()

adapSimple.Disp ose()

End Try

Nov 21 '05 #3
Can't believe I forgot to include the error message:
"System.Invalid OperationExcept ion: Update unable to find
TableMapping['Customers'] or DataTable 'Customers'.
at System.Data.Com mon.DbDataAdapt er.Update(DataS et dataSet, String
srcTable)
at ReadDB.frmReadD B.btnWrite_Clic k(Object sender, EventArgs e) in
C:\Documents and Settings\Diarmu id.RDATA\My Documents\Visua l Studio
2005\Projects\R eadDB\ReadDB\Re adDB\frmReadDB. vb:line 67"

Cor - what you sent doesn't compile. Datarow isn't declared, and I'm not
sure what should be in connectionsStri ng.
I'm also confused on what use conConnect and cmdSimple are for.

Thanks
Diarmuid
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uV******** ******@TK2MSFTN GP10.phx.gbl...
Diarmuid,

Changed in this message so watch typos.

\\\\
dim conConnect as new OleDbConnection (connectionsStr ing)
Dim stSQL As String = "SELECT * FROM Customers"
Dim adapSimple As New OleDbDataAdapte r(stSQL, conCONNECT)
Dim dsSimple As New Data.DataSet
Try
adapSimple.Fill (dsSimple)
Catch ex As exception
End Try
For Each rowSimple as DataRow In dsSimple.Tables (0).Rows
rowSimple("Cust omerName") &= " X"
Next
dim cmbSimple as new OleDBCommandBui lder(adapSimple )
Try
adapSimple.Upda te(dsSimple, "Customers" )
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
///

I hope this helps,

Cor

Nov 21 '05 #4
Dirarmuid,

How did you make your connection object.

You are in my idea partially using the designer and partially not.

If you use the designer than the only thing you have to do is to use the
created adapter and for sure not create a new command with a new sql string,
that will probably conflict with the insert, update and delete command.

I created a sample that does not use that designer at all.

I hope this helps,

Cor
Nov 21 '05 #5
No designer - everything is in the code I sent. Its reads the data
correctly - the rowSimple has the correct customer name. Its just the update
is the prob.

I cut and paste your example, and as mentioned, it does not compile.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OE******** ********@TK2MSF TNGP10.phx.gbl. ..
Dirarmuid,

How did you make your connection object.

You are in my idea partially using the designer and partially not.

If you use the designer than the only thing you have to do is to use the
created adapter and for sure not create a new command with a new sql
string, that will probably conflict with the insert, update and delete
command.

I created a sample that does not use that designer at all.

I hope this helps,

Cor

Nov 21 '05 #6

"Diarmuid" <di******@deads pam.com> schreef in bericht
news:u1******** *****@tk2msftng p13.phx.gbl...
No designer - everything is in the code I sent. Its reads the data
correctly - the rowSimple has the correct customer name. Its just the
update is the prob.


You mean that you can connect to a database server without a connection?

Great, however I am not that kind of wizard.

Success

Cor
Nov 21 '05 #7
Hi,

Just a comment. I see that you have a SELECT statement to fill your dataset,
which is of course normal. You are using the DataAdapter for updating but I
don't see any update string (strUpdate = "UPDATE ............... ...."), nor
update sqlcommand and finally you have not set your da.UpdateComman d. I
think you are missing some key elements in your code.

HTH, Phil

"Diarmuid" <di******@deads pam.com> wrote in message
news:u1******** *****@tk2msftng p13.phx.gbl...
No designer - everything is in the code I sent. Its reads the data
correctly - the rowSimple has the correct customer name. Its just the
update is the prob.

I cut and paste your example, and as mentioned, it does not compile.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OE******** ********@TK2MSF TNGP10.phx.gbl. ..
Dirarmuid,

How did you make your connection object.

You are in my idea partially using the designer and partially not.

If you use the designer than the only thing you have to do is to use the
created adapter and for sure not create a new command with a new sql
string, that will probably conflict with the insert, update and delete
command.

I created a sample that does not use that designer at all.

I hope this helps,

Cor


Nov 21 '05 #8
Oh right, I think I see what you mean. Thanks.

"Phil G." <Ph**@nospam.co m> wrote in message
news:df******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
Hi,

Just a comment. I see that you have a SELECT statement to fill your
dataset, which is of course normal. You are using the DataAdapter for
updating but I don't see any update string (strUpdate = "UPDATE
............... ...."), nor update sqlcommand and finally you have not set
your da.UpdateComman d. I think you are missing some key elements in your
code.

HTH, Phil

"Diarmuid" <di******@deads pam.com> wrote in message
news:u1******** *****@tk2msftng p13.phx.gbl...
No designer - everything is in the code I sent. Its reads the data
correctly - the rowSimple has the correct customer name. Its just the
update is the prob.

I cut and paste your example, and as mentioned, it does not compile.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:OE******** ********@TK2MSF TNGP10.phx.gbl. ..
Dirarmuid,

How did you make your connection object.

You are in my idea partially using the designer and partially not.

If you use the designer than the only thing you have to do is to use the
created adapter and for sure not create a new command with a new sql
string, that will probably conflict with the insert, update and delete
command.

I created a sample that does not use that designer at all.

I hope this helps,

Cor



Nov 21 '05 #9
> Great, however I am not that kind of wizard.

Cor - do I sense some sarcasm here? ;)
Dim custCB As OleDbCommandBui lder = New OleDbCommandBui lder(adapSimple )
is the line I was missing, and the table mapping error seems to be because I
didn't declare the table name when I filled the dataset.
Anyway, this is what worked in the end
Dim stQuery As String = "SELECT * FROM Customers"
Dim stTableName As String = "Customers"
Dim adapSimple As New OleDbDataAdapte r(stQuery, conCONNECT)
Dim dsSimple As New Data.DataSet
Dim rowSimple As Data.DataRow
Dim custCB As OleDbCommandBui lder = New OleDbCommandBui lder(adapSimple )

adapSimple.Fill (dsSimple, stTableName)
For Each rowSimple In dsSimple.Tables (stTableName).R ows
rowSimple("Cust omerName") &= " B"
Next

Try
adapSimple.Upda te(dsSimple, stTableName)

Catch ex As Exception
MsgBox(ex.ToStr ing)

Finally
dsSimple.Dispos e()
adapSimple.Disp ose()
End Try
Nov 21 '05 #10

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

Similar topics

4
2627
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when I create a new record/row I'm successfully updating the Access database, once the Update is...
1
2108
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a Database. (Disconnected Datasets). The problem I have is a new SqlAdapter is required before updating the Database: Therefore, to allow the update I have to do the following:
3
1994
by: Steven Blair | last post by:
Hi, I have a problem understanding the SqlDataAdaptor and the DataSet. I have a dll which has various methods for running stored procedures etc. It also has a method which allows the client to return a DataSet from a table. The client can modify this DataSet and I have wrote a function which will take this DataSet back in and update the Database. I assume this is what is meant with disconnected datasets?
4
2406
by: Wes | last post by:
Hello, I have an application using an xml dataset to store app and user settings. The problem I am having is related to writexml. I have a save button on my application that updates the dataset and then using the writexml(...) function saves the dataset to an xml file. I have noticed that the file does not change everytime I click the save button. I get no errors but the writexml function does not seem to be updating the xml file. ...
5
2045
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
14
2136
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
2
13973
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
1
2041
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and deletion or insertion in the dataset but when I am updating the
15
1820
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders) ' Save any changes.
3
2078
by: sachinkale123 | last post by:
I am using SQL Adapter to select data from a table in SQL Server Database. After creating Object I am filling that to a datatable. Assum that dataset has 5 row. After that I m updating that dataset and add 3 more rows. but not able to update that dataset to database table. My code is following. SqlDataAdapter SDA = new SqlDataAdapter("Select * from WFF", DAC.Conn); SDA.Fill(dt,"WFF"); //Updates dt here SDA.Update(dt); It does...
0
10494
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
10534
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
10207
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
9317
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...
0
6951
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
5619
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
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
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
3
3076
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.