开发者

dataadpter to insert records in existing data table

i am using the following code to insert a datatable to an existing table of 开发者_如何学JAVAdatabase but it's giving exception "Update requires a valid InsertCommand when passed DataRow collection with new rows"

where query is select * from placed_student

  public Boolean insert(string query, DataTable dt)
        {
            try
            {
                SqlDataAdapter sqlDA = new SqlDataAdapter(query, _sqlCon);
                DataTable dtValues = new DataTable();
                sqlDA.Fill(dtValues);
                sqlDA.Update(dt);
                return false;
            }
            catch(Exception ex)
            {
                logger.Error("Error when executing Query ", ex);
                return false;
            }
        }


Use SqlCommandBuilder to generate the InsertCommand for your DA.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜