关于"SqlCommandBuilder 实现批量更新"有紧急问题提问?

piao20040506 2008-06-03 04:29:23
源代码如下,曾经成功过,几天没运行开始报错如下:
"Update 无法找到 TableMapping['t_product'] 或 DataTable“t_product”。"
真是奇怪了,怎么就找不到我的表了呢!差了ds没问题啊,不知还会那里有错,有经验的老兄指教以下!!
#region DataGridView数据批量保存

public DataSet DataSetUpdateByDataSet(DataSet ds,string str_sql,string strTblName)
{
MessageBox.Show(ds.ToString());
SqlConnection conn = this.getcon();
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand((str_sql + strTblName), conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
try
{
lock (this) //处理并发情况(分布式情况)
{
myAdapter.Update(ds, strTblName);
}
}
catch (Exception err)
{

throw err;
}
finally
{
conn.Close();
}
return ds; //数据集的行状态在更新后会都变为: UnChange,在这次更新后客户端要用返回的ds
}
#endregion
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
piao20040506 2008-06-04
  • 打赏
  • 举报
回复
我有空格的!!
[Quote=引用 1 楼 amandag 的回复:]
有可能使sql语句最后和表名拼接的时候少了空格

SqlCommand myCommand = new SqlCommand((str_sql + strTblName), conn);
==
SqlCommand myCommand = new SqlCommand((str_sql + " " + strTblName), conn);
[/Quote]
amandag 2008-06-03
  • 打赏
  • 举报
回复
有可能使sql语句最后和表名拼接的时候少了空格

SqlCommand myCommand = new SqlCommand((str_sql + strTblName), conn);
==
SqlCommand myCommand = new SqlCommand((str_sql + " " + strTblName), conn);

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧