473,413 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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

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
Nov 19 '05 #1
1 4554
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/de...pdatetopic.asp

"Pe**********@ua.net" 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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: compuglobalhypermeganetz0r | last post by:
I am having trouble getting an adapter to update my access database, it gives the error Syntax error in INSERT INTO statement. for Line 98: Adapter.Update(WineDS, "tblWines") Below is my...
17
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset...
7
by: GatorBait | last post by:
Hi all, I am having a problem with my data adapter update command. I have generated the data adapter in the IDE and then I built a dataset. The dataset can get changed in the program and I...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
3
by: optictygre | last post by:
Hi folks. I have a couple questions about updating data from a dataset to a database using a data adapter. If I declare an adapter, set the batchupdatesize property to 0, and then call the...
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
0
by: Stardust | last post by:
Hello everyone! I am new to VB.NET so please accept my apologies if the question is too easy. I created a concise code to explain the problem I have. I have an Access database that contains...
4
by: bogdan | last post by:
Hi, I have a stored procedure that deletes a record in db. I created a DataSet (xsd) which auto-generated code for a table adapter. The adapter's select, insert, update, and delete methods...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.