TableAdapter.Update()不起作用 [英] TableAdapter.Update() doesn't work

查看:227
本文介绍了TableAdapter.Update()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用visual c#2008 xpress,sql srver 2005 xpress

数据集是ItemDataDS



这就是我的工作:





i'm using visual c# 2008 xpress, sql srver 2005 xpress
the dataset is ItemDataDS

that's what i do :

SA.ItemDataDSTableAdapters.tblItemDataTableAdapter taItemData;
ItemDataDS ds = new ItemDataDS();
DataTable dt = ds.Tables[tablename];





i创建并填充对象数组ao和do:dt。 LoadDataRow(ao,true);

当我检查ds(调试)时我找到了表格并在表格中找到了数据



最后我做:



i create and populate an array of objects ao and do : dt.LoadDataRow(ao,true);
when i check ds (debug) i find the table and in the table i find the data

finally i do :

taItemData.Update(ds);





这是完成没有和错误但是当我检查db-table没有写入数据



TableAdapters insert-,update-,select-和delete-方法工作,因为我添加并更新了一条记录数据集设计器。

fill()方法也有效'因为这条记录可以在ds中看到。



任何建议我是什么我做错了或我能做些什么来分析问题?

提前感谢



this is done without and error but when i check the db-table no data was written

the TableAdapters insert-, update-, select- and delete-methods work as i added and updated one record with the dataset-designer.
the fill() method also works 'cause this record can be seen in the ds.

any suggestions what i'm doing wrong or what i can do analyze the problem ?
thanks in advance

推荐答案

阅读以下详细教程: http://weblogs.asp.net/scottgu/archive/2006/01/15/Building-a-DAL-using-Strongly-Typed -TableAdapters-and-DataTables-in-VS-2005-and-ASP.NET-2.0.aspx [ ^ ]
Read the following detailed tutorial : http://weblogs.asp.net/scottgu/archive/2006/01/15/Building-a-DAL-using-Strongly-Typed-TableAdapters-and-DataTables-in-VS-2005-and-ASP.NET-2.0.aspx[^]


您好,



您可能需要为dataadapter设置insert,update和delete命令。



Hi,

You might need to set the insert, update and delete command for your dataadapter.

SqlCommandBuilder cmdbuilder;
cmdbuilder = new SqlCommandBuilder(dataAdapt);
 

dataAdapt.DeleteCommand = cmdbuilder.GetDeleteCommand(true);
dataAdapt.UpdateCommand = cmdbuilder.GetUpdateCommand(true);
dataAdapt.InsertCommand = cmdbuilder.GetInsertCommand(true);







最好的问候

Muthuraja




Best Regards
Muthuraja


您可能想要使用sqlcommandbuilder。

ex:< br $>


You might want to use sqlcommandbuilder.
ex:

SqlDataAdapter m_DataAdapter;           /* data adapter */
ItemDataDS ds = new ItemDataDS();       /* dataset */
DataTable dt = ds.Tables[tablename];    /* datatable */
SqlCommandBuilder m_ComBuilder;         /* command builder */

private void LoadData()                 /*populate your dataset*/
{
 m_DataAdapter = new SqlDataAdapter("Select ... from ..",Connection)
 m_DataAdapter.Fill(ds.Tables[tablename]);
}





...在数据表上添加行或进行更改





... add row or make changes on your datatable

private void SaveChanges()              /* Save all changes made */

{
m_ComBuilder = new SqlCommandBuilder(m_DataAdapter);
   m_DataAdapter.Update(ds.Tables[tablename]);
}


这篇关于TableAdapter.Update()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆