PC Review


Reply
Thread Tools Rate Thread

Updating the database with the dataset data????

 
 
Jon S via DotNetMonster.com
Guest
Posts: n/a
 
      13th Oct 2005
Hi all,
I'm trying to update the target database with the data thats in the target
dataset. I've included the snippit of code that is populating the target
dataset. When I loop round I see the source dataset give data to the target
dataset. I just don't know how to update the target database with the target
dataset.
Any help will be much appreciated???
Thanks, Dan.

if( tbl_Target.Rows.Count > -1 )
{
foreach(DataColumn col_Source in tbl_Source.Columns) //Create column object
to go through each column in table (source).
{
DataRow row_Target = tbl_Target.Rows[0]; //Create row object to state which
row to work on.
string str_ColNameSource; //Variable to hold the name of each column.
row_Target.BeginEdit();
str_ColNameSource = col_Source.ColumnName;
row_Target[str_ColNameSource] = row_Source[str_ColNameSource];
row_Target.EndEdit();
da_Target.Update(ds_Target, "Layouts");
}
}


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...o-net/200510/1
 
Reply With Quote
 
 
 
 
Christiaan van Bergen
Guest
Posts: n/a
 
      13th Oct 2005
Hi Jon,

Though I don't have enough info, my first rewrite of your code is

if( tbl_Target.Rows.Count > 0 )
{
DataRow row_Target = tbl_Target.Rows[0];//Create row object to state
which row to work on.
row_Target.bBeginEdit();
foreach(DataColumn col_Source in tbl_Source.Columns) //Create column
object to go through each column in table (source).
{
if (row_Target.Tables.Columns.Contains(col_Source.ColumnName))
row_Target[col_Source.ColumnName] =
row_Source[col_Source.ColumnName];
}
row_Target.EndEdit();
da_Target.Update(ds_Target);
}

In this I assume that
tbl_Target is a DataTable drawn from ds_Target
you only want to UPDATE one row (the first) in tbl_Target with data from
one (the first) row in tbl_Source
there are no auto-incremental fields present

HTH
Christiaan


"Jon S via DotNetMonster.com" <u2272@uwe> schreef in bericht
news:55c60f9d0e34e@uwe...
> Hi all,
> I'm trying to update the target database with the data thats in the target
> dataset. I've included the snippit of code that is populating the target
> dataset. When I loop round I see the source dataset give data to the
> target
> dataset. I just don't know how to update the target database with the
> target
> dataset.
> Any help will be much appreciated???
> Thanks, Dan.
>
> if( tbl_Target.Rows.Count > -1 )
> {
> foreach(DataColumn col_Source in tbl_Source.Columns) //Create column
> object
> to go through each column in table (source).
> {
> DataRow row_Target = tbl_Target.Rows[0]; //Create row object to state
> which
> row to work on.
> string str_ColNameSource; //Variable to hold the name of each column.
> row_Target.BeginEdit();
> str_ColNameSource = col_Source.ColumnName;
> row_Target[str_ColNameSource] = row_Source[str_ColNameSource];
> row_Target.EndEdit();
> da_Target.Update(ds_Target, "Layouts");
> }
> }
>
>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/For...o-net/200510/1



 
Reply With Quote
 
 
 
 
Jon S via DotNetMonster.com
Guest
Posts: n/a
 
      13th Oct 2005
Hey Christiaan,
Lovely piece of code, thanks very much.


Christiaan van Bergen wrote:
>Hi Jon,
>
>Though I don't have enough info, my first rewrite of your code is
>
> if( tbl_Target.Rows.Count > 0 )
> {
> DataRow row_Target = tbl_Target.Rows[0];//Create row object to state
>which row to work on.
> row_Target.bBeginEdit();
> foreach(DataColumn col_Source in tbl_Source.Columns) //Create column
>object to go through each column in table (source).
> {
> if (row_Target.Tables.Columns.Contains(col_Source.ColumnName))
> row_Target[col_Source.ColumnName] =
>row_Source[col_Source.ColumnName];
> }
> row_Target.EndEdit();
> da_Target.Update(ds_Target);
> }
>
>In this I assume that
> tbl_Target is a DataTable drawn from ds_Target
> you only want to UPDATE one row (the first) in tbl_Target with data from
>one (the first) row in tbl_Source
> there are no auto-incremental fields present
>
>HTH
>Christiaan
>
>> Hi all,
>> I'm trying to update the target database with the data thats in the target

>[quoted text clipped - 24 lines]
>> }
>> }



--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...o-net/200510/1
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
updating dataset from aspx not updating? Rich Microsoft ASP .NET 2 24th Mar 2004 04:01 AM
Error in updating database table from a dataset Simon Verona Microsoft ADO .NET 6 28th Jan 2004 11:28 PM
Updating SQL database from a Dataset object Herb Stull Microsoft ADO .NET 2 24th Sep 2003 12:03 AM
Updating database from Typed Dataset without loading entire database Jeremy Summers Microsoft ADO .NET 2 10th Sep 2003 06:48 PM
Problem updating existing typed dataset from Generate Dataset designer Eric Kennedy Microsoft ADO .NET 0 29th Aug 2003 05:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 AM.