{
string selectDesc = @" SELECT [Descripion id], [Sub Collection FROM Descripion ";
DataSet dsD = new DataS开发者_StackOverflowet();
SqlCommand comD = new SqlCommand();
comD.Connection = con;
comD.CommandText = selectDesc;
SqlDataAdapter daD = new SqlDataAdapter();
daD.SelectCommand = comD;
SqlCommandBuilder cbD = new SqlCommandBuilder(da);
daD.Fill(dsD, "Descripion");
DataRow new_row_Desc = dsD.Tables[0].NewRow();
new_row_Desc["Descripion id"] = 58589;
new_row_Desc["Sub Collection"] = TextBox18.Text;
dsD.Tables[0].Rows.Add(new_row_Desc);
daD.Update(dsD.Tables[0]);
}
I am getting this error:
Update requires a valid InsertCommand when passed DataRow collection with new rows.
What is the problem?
First of all, your select statement is missing a closing "]" before FROM
. Also, you're assigning a select command to the data adapter, but no insert and update commands. So the data adapter does not know what to do when inserting a new row.
精彩评论