ADO.NET Adapter.Update() what's wrong in my Code

Discussion in 'ASP .Net' started by Guest, Dec 21, 2004.

  1. Guest

    Guest Guest

    I will be add Data in my Example Database. I have this Code by a ASP.NET Book but this will not work. Error message: Operation must be a actually Query use.
    Error in: adapter.Update(dataset,"Authors");


    My Code:

    private void bt_add_Click(object sender, System.EventArgs e)
    {
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
    @"Data Source=c:\aspnet_gup.mdb");
    conn.Open();
    string SQL = "SELECT * FROM Authors";
    OleDbDataAdapter adapter = new OleDbDataAdapter(new OleDbCommand(SQL,conn));
    OleDbCommandBuilder custCB = new OleDbCommandBuilder(adapter);
    DataSet dataset = new DataSet();
    adapter.Fill(dataset,"Authors");

    DataRow row = dataset.Tables["Authors"].NewRow();
    row["Firstname"]=tb_firstname.Text;
    row["Lastname"] =tb_lastname.Text;

    dataset.Tables["Authors"].Rows.Add(row);

    adapter.Update(dataset,"Authors");
    dataset.Tables["Authors"].Clear();
    adapter.Fill(dataset,"Authors");

    myDataGrid.EditItemIndex= -1;
    myDataGrid.DataSource= dataset;
    DataBind();
    conn.Close();


    }

    Thank you for you help

    Peter
    Guest, Dec 21, 2004
    #1
    1. Advertising

  2. you cannot call this method passing 2 parameters. The dataadapter.update()
    accepts a dataset object. So to get to the tables authors you would have to
    do something like this

    adapter.update(dataset.tables("authors"))

    look here for the ducumentation:
    http://msdn.microsoft.com/library/d...stemdatacommondataadapterclassupdatetopic.asp



    "" wrote:

    > I will be add Data in my Example Database. I have this Code by a ASP.NET Book but this will not work. Error message: Operation must be a actually Query use.
    > Error in: adapter.Update(dataset,"Authors");
    >
    >
    > My Code:
    >
    > private void bt_add_Click(object sender, System.EventArgs e)
    > {
    > OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
    > @"Data Source=c:\aspnet_gup.mdb");
    > conn.Open();
    > string SQL = "SELECT * FROM Authors";
    > OleDbDataAdapter adapter = new OleDbDataAdapter(new OleDbCommand(SQL,conn));
    > OleDbCommandBuilder custCB = new OleDbCommandBuilder(adapter);
    > DataSet dataset = new DataSet();
    > adapter.Fill(dataset,"Authors");
    >
    > DataRow row = dataset.Tables["Authors"].NewRow();
    > row["Firstname"]=tb_firstname.Text;
    > row["Lastname"] =tb_lastname.Text;
    >
    > dataset.Tables["Authors"].Rows.Add(row);
    >
    > adapter.Update(dataset,"Authors");
    > dataset.Tables["Authors"].Clear();
    > adapter.Fill(dataset,"Authors");
    >
    > myDataGrid.EditItemIndex= -1;
    > myDataGrid.DataSource= dataset;
    > DataBind();
    > conn.Close();
    >
    >
    > }
    >
    > Thank you for you help
    >
    > Peter
    >
    >
    >
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=, Dec 21, 2004
    #2
    1. Advertising

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. nita
    Replies:
    1
    Views:
    843
    Saravana
    Nov 20, 2004
  2. ronaldlee

    Transfer ADO Code to ADO.NET

    ronaldlee, Dec 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    Kevin Spencer
    Dec 17, 2004
  3. Replies:
    0
    Views:
    1,291
  4. abentov
    Replies:
    0
    Views:
    323
    abentov
    Aug 11, 2006
  5. Navin
    Replies:
    1
    Views:
    658
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page