开发者

dataadpter to insert records in existing data table

开发者 https://www.devze.com 2023-01-13 04:08 出处:网络
i am using the following code to insert a datatable to an existing table of 开发者_如何学JAVAdatabase

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

精彩评论

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