473,322 Members | 1,806 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,322 software developers and data experts.

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.Update(dsSimple, "Customers")

What should I be doing instead?
Thanks
Diarmuid

Dim stSQL As String = "SELECT * FROM Customers"

Dim adapSimple As New OleDbDataAdapter(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("CustomerName") &= " X"

Next

adapSimple.Update(dsSimple, "Customers")

Catch ex As Exception

MsgBox(ex.ToString)

Finally

dsSimple.Dispose()

adapSimple.Dispose()

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

Changed in this message so watch typos.

\\\\
dim conConnect as new OleDbConnection(connectionsString)
Dim stSQL As String = "SELECT * FROM Customers"
Dim adapSimple As New OleDbDataAdapter(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("CustomerName") &= " X"
Next
dim cmbSimple as new OleDBCommandBuilder(adapSimple)
Try
adapSimple.Update(dsSimple, "Customers")
Catch ex As Exception
MsgBox(ex.ToString)
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******@deadspam.com> wrote in message
news:ey**************@TK2MSFTNGP15.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.Update(dsSimple, "Customers")

What should I be doing instead?
Thanks
Diarmuid

Dim stSQL As String = "SELECT * FROM Customers"

Dim adapSimple As New OleDbDataAdapter(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("CustomerName") &= " X"

Next

adapSimple.Update(dsSimple, "Customers")

Catch ex As Exception

MsgBox(ex.ToString)

Finally

dsSimple.Dispose()

adapSimple.Dispose()

End Try

Nov 21 '05 #3
Can't believe I forgot to include the error message:
"System.InvalidOperationException: Update unable to find
TableMapping['Customers'] or DataTable 'Customers'.
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at ReadDB.frmReadDB.btnWrite_Click(Object sender, EventArgs e) in
C:\Documents and Settings\Diarmuid.RDATA\My Documents\Visual Studio
2005\Projects\ReadDB\ReadDB\ReadDB\frmReadDB.vb:li ne 67"

Cor - what you sent doesn't compile. Datarow isn't declared, and I'm not
sure what should be in connectionsString.
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**************@TK2MSFTNGP10.phx.gbl...
Diarmuid,

Changed in this message so watch typos.

\\\\
dim conConnect as new OleDbConnection(connectionsString)
Dim stSQL As String = "SELECT * FROM Customers"
Dim adapSimple As New OleDbDataAdapter(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("CustomerName") &= " X"
Next
dim cmbSimple as new OleDBCommandBuilder(adapSimple)
Try
adapSimple.Update(dsSimple, "Customers")
Catch ex As Exception
MsgBox(ex.ToString)
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****************@TK2MSFTNGP10.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******@deadspam.com> schreef in bericht
news:u1*************@tk2msftngp13.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.UpdateCommand. I
think you are missing some key elements in your code.

HTH, Phil

"Diarmuid" <di******@deadspam.com> wrote in message
news:u1*************@tk2msftngp13.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****************@TK2MSFTNGP10.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.com> 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.UpdateCommand. I think you are missing some key elements in your
code.

HTH, Phil

"Diarmuid" <di******@deadspam.com> wrote in message
news:u1*************@tk2msftngp13.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****************@TK2MSFTNGP10.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 OleDbCommandBuilder = New OleDbCommandBuilder(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 OleDbDataAdapter(stQuery, conCONNECT)
Dim dsSimple As New Data.DataSet
Dim rowSimple As Data.DataRow
Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(adapSimple)

adapSimple.Fill(dsSimple, stTableName)
For Each rowSimple In dsSimple.Tables(stTableName).Rows
rowSimple("CustomerName") &= " B"
Next

Try
adapSimple.Update(dsSimple, stTableName)

Catch ex As Exception
MsgBox(ex.ToString)

Finally
dsSimple.Dispose()
adapSimple.Dispose()
End Try
Nov 21 '05 #10
Diarmuid,

Greath, however why are those two disposes and better is to set the fill as
well in a try and catch block as I showed you?

Cor
Nov 21 '05 #11
Good point about the try before the fill.
Don't you need to dispose once you are finished with the object? I thought I
read that somewhere.
And thanks for your help.
Diarmuid

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Diarmuid,

Greath, however why are those two disposes and better is to set the fill
as well in a try and catch block as I showed you?

Cor

Nov 21 '05 #12

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

Similar topics

4
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,...
1
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...
3
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...
4
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...
5
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...
14
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...
2
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
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...
15
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.