0
string qry="select *from mom";
Dataset dataset= new Dataset();
SqlDataAdapteradap adap= new SqlDataAdapter(qry,con);
adap.Fill(dataset,"MOM");
DataRow drow = dataset.Tables["MOM"].NewRow();
drow[0] = MRefDDL.SelectedItem.Text;
drow[1] = project.Text.Trim();
drow[2] = agendatopic3.Text.Trim();
drow[3] = presenter3.Text.Trim();
drow[4] = discus.Text.Trim();
drow[5] = conclu.Text.Trim();
drow[6] = "1";
dataset.Tables["MOM"].Rows.Add(drow);
adap = new SqlDataAdapter();
adap.Update(dataset, "MOM");

Here I have One Dataset with MOM Table which fill by data adapter when after add new row into data set. iwant add this row into database table with help of adapter.update() Method.But its giving me error:- Update requires a valid InsertCommand when passed DataRow collection with new rows.

Gaur Puneet
  • 1
  • 1
  • 2
  • 6

2 Answers2

0

In the dataadapter, there are insert, update and delete queries that you need to add. The wizard can also do that for you. You can also:

adp.InsertCommand = New SqlCommand(sql, connection)

etc.

Look at https://stackoverflow.com/a/21239695/1662973 for more detailed info.

Community
  • 1
  • 1
Anthony Horne
  • 2,522
  • 2
  • 29
  • 51
0

you are reinitializing the dataadapter just before the Update() method. Please comment this.

//adap = new SqlDataAdapter(); // make this line comment 
adap.Update(dataset, "MOM");
Sain Pradeep
  • 3,119
  • 1
  • 22
  • 31