0
votes
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.

2
now its giving me this error :The DataAdapter.SelectCommand property needs to be initialized. - Gaur Puneet

2 Answers

0
votes

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.

0
votes

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

//adap = new SqlDataAdapter(); // make this line comment 
adap.Update(dataset, "MOM");