Updating the database with the dataset data????

Discussion in 'Microsoft ADO .NET' started by Jon S via DotNetMonster.com, Oct 13, 2005.

  1. 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/Forums.aspx/dotnet-ado-net/200510/1
     
    Jon S via DotNetMonster.com, Oct 13, 2005
    #1
    1. Advertisements

  2. 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/Forums.aspx/dotnet-ado-net/200510/1
     
    Christiaan van Bergen, Oct 13, 2005
    #2
    1. Advertisements

  3. 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/Forums.aspx/dotnet-ado-net/200510/1
     
    Jon S via DotNetMonster.com, Oct 13, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Kennedy
    Replies:
    0
    Views:
    426
    Eric Kennedy
    Aug 29, 2003
  2. Jeremy Summers
    Replies:
    2
    Views:
    331
  3. Herb Stull

    Updating SQL database from a Dataset object

    Herb Stull, Sep 23, 2003, in forum: Microsoft ADO .NET
    Replies:
    2
    Views:
    191
    William Ryan
    Sep 24, 2003
  4. Simon Verona

    Error in updating database table from a dataset

    Simon Verona, Jan 28, 2004, in forum: Microsoft ADO .NET
    Replies:
    6
    Views:
    311
    Blake Weaver
    Jan 28, 2004
  5. Guest

    data updating from dataset to database problem

    Guest, May 22, 2006, in forum: Microsoft ADO .NET
    Replies:
    0
    Views:
    164
    Guest
    May 22, 2006
Loading...

Share This Page