【问题标题】:dataadpter to insert records in existing data tabledataadpter 在现有数据表中插入记录
【发布时间】:2010-08-27 17:05:39
【问题描述】:

我正在使用以下代码将数据表插入到现有的数据库表中 但它给出了异常“当通过新行传递 DataRow 集合时,更新需要有效的 InsertCommand”

其中查询是 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;
            }
        }

【问题讨论】:

  • 我还想知道将 100 条记录插入到现有数据库表中是不是最好的方法......或者存在一些更有效的方法,请让我知道同样的......

标签: asp.net


【解决方案1】:

使用 SqlCommandBuilder 为您的 DA 生成 InsertCommand。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多