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

Updating Dataset

Hello

To update a dataset i created a method (see below)
My question is, how to return the created Primary ID that is created on the
server auto incremential. Is there anyway to place that value into the
correct inserted row?

Kind regards

Johnny E. Jensen

#region Method 'Save'

public void Save(DataSet Datasource, object UserID)

{

bool IsValid = true;

if (Datasource != null)

{

if (Datasource.Tables[0] != null)

{

DataSet dsChanges = Datasource.GetChanges();

if (dsChanges != null)

{

OleDbConnection con = new OleDbConnection(_ConnectionString);

try

{

con.Open();

}

catch (Exception ex)

{

ErrorLogger.WriteToErrorLog(ex.Message, ex.StackTrace,
"Aware.Database.Save()");

IsValid = false;

}

if (IsValid == true)

{

OleDbTransaction dbTran = con.BeginTransaction();

DataTable dtChanges = dsChanges.Tables[0];

OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + dtChanges.TableName
+ "]", con);

cmd.Transaction = dbTran;

OleDbDataAdapter dbAdapter = new OleDbDataAdapter(cmd);

dbAdapter.RowUpdated += new
OleDbRowUpdatedEventHandler(dbAdapter_RowUpdated);

OleDbCommandBuilder cb = new OleDbCommandBuilder(dbAdapter);

try

{

dbAdapter.InsertCommand = cb.GetInsertCommand();

}

catch (Exception ex)

{

ErrorLogger.WriteToErrorLog(ex.Message, ex.StackTrace,
"Aware.Database.Save()");

}

try

{

dbAdapter.UpdateCommand = cb.GetUpdateCommand();

}

catch (Exception ex)

{

ErrorLogger.WriteToErrorLog(ex.Message, ex.StackTrace,
"Aware.Database.Save()");

}

try

{

dbAdapter.DeleteCommand = cb.GetDeleteCommand();

}

catch (Exception ex)

{

ErrorLogger.WriteToErrorLog(ex.Message, ex.StackTrace,
"Aware.Database.Save()");

}

if (dbAdapter.InsertCommand != null)

dbAdapter.InsertCommand.Transaction = dbTran;

if (dbAdapter.UpdateCommand != null)

dbAdapter.UpdateCommand.Transaction = dbTran;

if (dbAdapter.DeleteCommand != null)

dbAdapter.DeleteCommand.Transaction = dbTran;

try

{

dbAdapter.Update(dtChanges);

}

catch (Exception ex)

{

ErrorLogger.WriteToErrorLog(ex.Message, ex.StackTrace,
"Aware.Database.Save()");

}

TableLogger(Datasource, UserID);

Datasource.AcceptChanges();

dbTran.Commit();

con.Close();

dsChanges = null;

con = null;

dbTran = null;

dtChanges = null;

cmd = null;

dbAdapter = null;

cb = null;

}

}

}

}

}




Oct 2 '07 #1
1 1478
http://msdn2.microsoft.com/en-us/lib...t0(vs.71).aspx
"Johnny E. Jensen" <jo****@XXemde.dkwrote in
news:#3**************@TK2MSFTNGP06.phx.gbl:
Hello

To update a dataset i created a method (see below)
My question is, how to return the created Primary ID that is created
on the server auto incremential. Is there anyway to place that value
into the correct inserted row?

Kind regards

Johnny E. Jensen
Oct 2 '07 #2

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

Similar topics

0
by: Robin | last post by:
In a .Net solution that has a DAL, Class and Business logic. When recreating a dataset from the class the records are inserted into the database from the dataset instead of updating. This is using...
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...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
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...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
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();
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
6
by: mike11d11 | last post by:
I'm trying to create an application that will have multiple users working off a table on a SQL server. Since multi users will be updating different records at any given moment, how can i get those...
0
by: OldStd | last post by:
Updating data using 2 data sets I am having some problems in updating the database using two datasets as suggested by someone. 1. Data is displayed in a data grid from a dataset generated using...
1
by: jonbartlam | last post by:
Hi There I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.