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
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