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

G

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top