public int UpdateByDataSet(DataSet ds,string strTblName,string strConnection)
{
try
{
SqlConnection conn = new SqlConnection(strConnection));
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand("select * from "+strTblName),(SqlConnection)this.conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds,strTblName);
return 0;
}
catch(BusinessException errBU)
{
throw errBU;
}
catch(Exception err)
{
throw new BusinessException(err);
}
}
请问这个函数是不是都将DS里的数据插入strTblName 中? 意思就是ds.tables[0].Rows[].RowState 都默认为Added? 对这个不熟。
{
try
{
SqlConnection conn = new SqlConnection(strConnection));
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand("select * from "+strTblName),(SqlConnection)this.conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds,strTblName);
return 0;
}
catch(BusinessException errBU)
{
throw errBU;
}
catch(Exception err)
{
throw new BusinessException(err);
}
}
请问这个函数是不是都将DS里的数据插入strTblName 中? 意思就是ds.tables[0].Rows[].RowState 都默认为Added? 对这个不熟。
解决方案 »
- 跪求帮助!调用PCI-Dask.dll,里面有个方法的参数是out关键字,怎么调用该方法?
- 怎么实现两个flowlayoutpanel里的按钮相互拖动
- 如何模拟出一个socket服务器发送ASCII码流到另一端
- 关于Page_Load()的问题
- StreamReader.ReadLine()读文本文件时,当一行大于162个字符时,出现数据丢失,如何对付?
- [新手求助]定义一副扑克取随机数并用对应图形展示
- 大家帮忙看看下面的正则表达式有问题吗?
- [求助]请问怎样让自己做的Widows应用程序一次只能启动一个?
- C#中的类型转换问题,急!
- 请问C#中的整数到底有几种类型,为什么书上说有九种,可我只见过八种!
- 请问熟悉c++的一个星期能用c#,不知是真是假?
- 关于网络编程
{
SqlConnection sqlcon = new SqlConnection("....");
SqlDataAdapter da = new SqlDataAdapter("select * from mytable", sqlcon);
DataSet ds = new DataSet();
da.Fill(ds, "mytable");
ds.WriteXml("C:\\1.xml");
} public static void XmlToSqlServer()
{
SqlConnection sqlcon = new SqlConnection("....");
SqlDataAdapter da = new SqlDataAdapter("select * from mytable", sqlcon);
DataSet ds = new DataSet();
ds.ReadXml("C:\\1.xml");
SqlCommandBuilder comb = new SqlCommandBuilder(da);
da.Update(ds, "mytable");
}
我这两个函数先DataToXml()再XmlToSqlServer()应该不出错啊(应该是完全update mytable,只是没变化才对)异常信息,违反了主键约束,他肯定是望里面插数据了才出错的。XmlToSqlServer里的ds默认rowstate都是added吗?是不是我新建的dataset第行状态都是added?
Modified和Deleted 是相对于上次凋用AcceptChanges()方法之后的操作.
da.insertcommand.transaction=tr这样?
da.updatecommand.transaction=tr这样?
da.deletecommand.transaction=tr这样?tr 是一个 SqlTransaction 对象。