473,486 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using Dataadapter to update Database

I am using the following code to update my database but it dosn't do the
update and it dosen't show any error:

SqlDataAdapter myDataAdapter=new SqlDataAdapter();

myDataAdapter.SelectCommand=new SqlCommand("select * from Alerts",conn);

DataSet alertDS = new DataSet();

myDataAdapter.FillSchema(alertDS,SchemaType.Source ,"Alerts");

myDataAdapter.Fill(alertDS);

DataTable myTable = alertDS.Tables[0];

foreach(DataRow myDRow in myTable.Rows)

{

sb.Append((String)(myDRow["Message"]));

myDRow["Viewed"]=1;
}

myDataAdapter.Update(alertDS,"Alerts");

=====End of code=====================

if I remove this line from code :

myDataAdapter.FillSchema(alertDS,SchemaType.Source ,"Alerts");

it gives me this error on the update on the adapter:

update requires a valid Update Command when passed DataRow collection with
modified rows

Is there somebody who can help me.

Thanks
Nov 16 '05 #1
1 2652
Hi ALI
For SqlDataadapter.Update() to work, you will need to set the
UpdateCommand property of the SqlDataAdapter object.
HTH.
r.

"ALI-R" <al*@microsoft.com> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
I am using the following code to update my database but it dosn't do the
update and it dosen't show any error:

SqlDataAdapter myDataAdapter=new SqlDataAdapter();

myDataAdapter.SelectCommand=new SqlCommand("select * from Alerts",conn);

DataSet alertDS = new DataSet();

myDataAdapter.FillSchema(alertDS,SchemaType.Source ,"Alerts");

myDataAdapter.Fill(alertDS);

DataTable myTable = alertDS.Tables[0];

foreach(DataRow myDRow in myTable.Rows)

{

sb.Append((String)(myDRow["Message"]));

myDRow["Viewed"]=1;
}

myDataAdapter.Update(alertDS,"Alerts");

=====End of code=====================

if I remove this line from code :

myDataAdapter.FillSchema(alertDS,SchemaType.Source ,"Alerts");

it gives me this error on the update on the adapter:

update requires a valid Update Command when passed DataRow collection with
modified rows

Is there somebody who can help me.

Thanks

Nov 16 '05 #2

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

Similar topics

3
2185
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I...
3
1853
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
9
1454
by: cherishman | last post by:
When I use self-defined database, sometimes the dataadapter can't auto create insertcommand, updatecommand and deletecommand, it just only create selectcommand? But when I use these database such...
3
8895
by: RSH | last post by:
Hi, I have a situation in where i have two instances of SQL server, the first is our Production Environment, the second is our Development environment. Both servers contain the same databases...
2
13935
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
5
5023
by: George | last post by:
I have set DataAdapter.AcceptChangesDuringUpdate = true; However, I find that I still need to call AcceptChanges on the associated DataTable, DataTable.AcceptChanges(); Has anyone...
1
2900
by: ankz | last post by:
Hi Guys I have got 3 tables - in Access Database with Student ID as primary Key in all and all tables are linked with 1 to 1 relationship. I have code the everying with manual program to...
3
2340
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
1
8197
by: joel | last post by:
hi guys... i am a student, i am studying and i am a newbie in VB.net and i am using SQL Server 2000. I have this datatable which i insert rows (may take up to 2 or more rows because i would...
11
4110
by: gyap88 | last post by:
Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
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
5434
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,...
1
4865
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
4559
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...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.