DataSet Update Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shahar

    #1

    DataSet Update Problem

    Hi what's worng with the following code, the chages I made is only
    change the DataSet but not the Data-Base:

    try
    {
    DataSet ds = new DataSet();

    OleDbDataAdapte r adapter = new OleDbDataAdapte r("Select * from
    Employees", @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=My.mdb") ;

    adapter.Fill(ds , "Employees" );

    ds.Tables["Employees"].Rows[0].BeginEdit();
    ds.Tables["Employees"].Rows[0]["name"] = "X";
    ds.Tables["Employees"].Rows[0].EndEdit();

    ds.AcceptChange s();
    adapter.Update( ds, "Employees" );

    foreach(DataRow row in ds.Tables["Employees"].Rows)
    {
    Console.WriteLi ne(row["id"] + " " + row["name"]);
    }
    }
    catch(Exception exp)
    {
    Console.WriteLi ne(exp.Message. ToString());
    }
  • Mikael Gustavsson

    #2
    Re: DataSet Update Problem

    Hi!

    Try removing the line

    ds.AcceptChange s();

    Since you do this before update the changes made to the dataset will not be
    stored in the database.

    //Mikael

    "Shahar" <shahar@log-on.com> wrote in message
    news:e803974e.0 308100041.20f9e 319@posting.goo gle.com...[color=blue]
    > Hi what's worng with the following code, the chages I made is only
    > change the DataSet but not the Data-Base:
    >
    > try
    > {
    > DataSet ds = new DataSet();
    >
    > OleDbDataAdapte r adapter = new OleDbDataAdapte r("Select * from
    > Employees", @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=My.mdb") ;
    >
    > adapter.Fill(ds , "Employees" );
    >
    > ds.Tables["Employees"].Rows[0].BeginEdit();
    > ds.Tables["Employees"].Rows[0]["name"] = "X";
    > ds.Tables["Employees"].Rows[0].EndEdit();
    >
    > ds.AcceptChange s();
    > adapter.Update( ds, "Employees" );
    >
    > foreach(DataRow row in ds.Tables["Employees"].Rows)
    > {
    > Console.WriteLi ne(row["id"] + " " + row["name"]);
    > }
    > }
    > catch(Exception exp)
    > {
    > Console.WriteLi ne(exp.Message. ToString());
    > }[/color]


    Comment

    Working...