using Dataadapter to update Database

A

ALI-R

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
 
R

Ranjan

Hi ALI
For SqlDataadapter.Update() to work, you will need to set the
UpdateCommand property of the SqlDataAdapter object.
HTH.
r.
 

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

Top