开发者

Problem with dataset to sql

{ 
   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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜