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

Can't save my data in the DB with ADO.NET

Hello,
I'm trying to save the changes back to the database, but it doesn't
work -could anybody help me?
I'm using a DataSet and the wierd thing is that I can save the changes in
the memory but not in the database :-/
I have tried to duplicate an example I found on msdn -but with no luck. The
sourcecode is in C#:

---------------------------------------------------------------------
Sourcecode
public void insertData(String tableName, ArrayList insertArray)
{
object[] iObj = new object[insertArray.Count];

for (int loopIndex = 0; loopIndex < insertArray.Count; loopIndex++)
{
iObj[loopIndex] = insertArray[loopIndex];
}

dataset.Tables[tableName].Rows.Add(iObj);
dataset.AcceptChanges();

autoGen = new OdbcCommandBuilder(oDataAdapter);
oDataAdapter.InsertCommand = autoGen.GetInsertCommand();

oTransaction = null;
oConnection = new OdbcConnection(myConnection);
oConnection.Open();
oTransaction = oConnection.BeginTransaction();
oDataAdapter.Update(dataset, tableName);
oTransaction.Commit();
oConnection.Close();
}
---------------------------------------------------------------------
Sourcecode

thanks

best regards
Torben
Nov 15 '05 #1
2 1622
Remove the AcceptChanges.

Invoking AcceptChanges means that the dataset will be set to current
version, will not have rows in inserted state anymore, so the Insert command
will not find any rows to insert.

Anyway, after a succesfull update of the adapter the AcceptChanges will be
called automatically by the .NET Framework.

Hope this helps

Dan Cimpoiesu

"Torben Madsen" <as*****@privat.dk> wrote in message
news:Oa*************@TK2MSFTNGP11.phx.gbl...
Hello,
I'm trying to save the changes back to the database, but it doesn't
work -could anybody help me?
I'm using a DataSet and the wierd thing is that I can save the changes in
the memory but not in the database :-/
I have tried to duplicate an example I found on msdn -but with no luck. The sourcecode is in C#:

---------------------------------------------------------------------
Sourcecode
public void insertData(String tableName, ArrayList insertArray)
{
object[] iObj = new object[insertArray.Count];

for (int loopIndex = 0; loopIndex < insertArray.Count; loopIndex++)
{
iObj[loopIndex] = insertArray[loopIndex];
}

dataset.Tables[tableName].Rows.Add(iObj);
dataset.AcceptChanges();

autoGen = new OdbcCommandBuilder(oDataAdapter);
oDataAdapter.InsertCommand = autoGen.GetInsertCommand();

oTransaction = null;
oConnection = new OdbcConnection(myConnection);
oConnection.Open();
oTransaction = oConnection.BeginTransaction();
oDataAdapter.Update(dataset, tableName);
oTransaction.Commit();
oConnection.Close();
}
---------------------------------------------------------------------
Sourcecode

thanks

best regards
Torben

Nov 15 '05 #2
Thanks Dan!
that did the trick :o)
"Dan Cimpoiesu" <da**********@gmx.net> skrev i en meddelelse
news:%2***************@TK2MSFTNGP10.phx.gbl...
Remove the AcceptChanges.

Invoking AcceptChanges means that the dataset will be set to current
version, will not have rows in inserted state anymore, so the Insert command will not find any rows to insert.

Anyway, after a succesfull update of the adapter the AcceptChanges will be
called automatically by the .NET Framework.

Hope this helps

Dan Cimpoiesu

"Torben Madsen" <as*****@privat.dk> wrote in message
news:Oa*************@TK2MSFTNGP11.phx.gbl...
Hello,
I'm trying to save the changes back to the database, but it doesn't
work -could anybody help me?
I'm using a DataSet and the wierd thing is that I can save the changes in the memory but not in the database :-/
I have tried to duplicate an example I found on msdn -but with no luck.

The
sourcecode is in C#:

---------------------------------------------------------------------
Sourcecode
public void insertData(String tableName, ArrayList insertArray)
{
object[] iObj = new object[insertArray.Count];

for (int loopIndex = 0; loopIndex < insertArray.Count; loopIndex++)
{
iObj[loopIndex] = insertArray[loopIndex];
}

dataset.Tables[tableName].Rows.Add(iObj);
dataset.AcceptChanges();

autoGen = new OdbcCommandBuilder(oDataAdapter);
oDataAdapter.InsertCommand = autoGen.GetInsertCommand();

oTransaction = null;
oConnection = new OdbcConnection(myConnection);
oConnection.Open();
oTransaction = oConnection.BeginTransaction();
oDataAdapter.Update(dataset, tableName);
oTransaction.Commit();
oConnection.Close();
}
---------------------------------------------------------------------
Sourcecode

thanks

best regards
Torben


Nov 15 '05 #3

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

Similar topics

1
by: ARobi | last post by:
I edit data from a form by using docmd.close acform, formname, acsaveyes. The form closes properly and returns the control to the father form as it should be. The problem is that when from the...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
2
by: Ben Turner | last post by:
I'm querying a web service to get some global weather data (http://www.webservicex.net/globalweather.asmx?WSDL) which works really well, however I'm getting stuck on the returned data for the...
5
by: Øyvind Isaksen | last post by:
I have a page with an optional integer-field, and one asp:calendar control. I use a stored procedure to save the data in SQL Server. When all fields contains data, the code works great! But if the...
2
by: Jim | last post by:
When I manually enter data into a bound textbox then point my cursor to my Save button and press Save the data I just entered data does not save. However if I move my cursor to another text box or...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
3
by: STEPHENSS | last post by:
Hi, I have a crystal report that has many subreports over many pages and Iam getting the following error Unable to save data with report, the save data is incomplete generate the saved data Yes...
1
by: QCLee | last post by:
Hello Sir, Im here again asking for help. I have a form and a subform relate to HVAC Windward Table. i have a SAVE button on the form that when clicked it saves data on the HVAC Windward Table but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.