删除dataset中相关表的记录,只需要在这些表之间建立关系就可以了。
解决方案 »
- 关于如何打印当前的FORM中的panel,求教~~~
- 求助,急!!关于 visual studio2008 程序发布安装之后,无法删除的问题
- 问form action问题
- VS2003 web.config 出现乱码
- 请问兄弟们一个gridview问题
- C# WebBrowser的DocumentCompleted事件(高手进)
- 我想问下,大家在做数据验证的时候,是怎么做,是选用WEB控件做控制,还是用JAVASCRIPT???如果用JAVASCRIPT做客户端的话,怎么实现好
- 做了个webservice.欢迎近来测试,来者给分
- c1 flexgrid 中能否进行以行为单位的复制?
- 有一个连锁超市,分布在同一坐城市的不同地方,我应该使用哪种方式?
- 请问哪位大侠能提供.NET环境下的COM或者COM+编程的资料(文字或者实例),谢谢!
- 分隔XML文件?
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=localhost;database=northWind;uid=sa;password=194910");
conn.Open();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from customers",conn);
dt = new System.Data.DataSet();
da.Fill(dt,"customers");
this.DataGrid.SetDataBinding(dt,"customers");删除的代码用如下:
this.BindingContext[dt,"customers"].RemoveAt(this.BindingContext[dt,"customers"].Position);更新的语句用如下 :
this.sqlDeleteCommand1.CommandText = @"DELETE FROM YZ_STAMPER WHERE (StamperID = @Original_StamperID) AND (EmployeeID = @Original_EmployeeID OR @Original_EmployeeID IS NULL AND EmployeeID IS NULL) AND (StamperName = @Original_StamperName OR @Original_StamperName IS NULL AND StamperName IS NULL) AND (State = @Original_State OR @Original_State IS NULL AND State IS NULL)";
this.sqlDeleteCommand1.Connection = this.conn;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_StamperID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "StamperID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_EmployeeID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "EmployeeID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_StamperName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "StamperName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_State", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "State", System.Data.DataRowVersion.Original, null));
// conn.Open();
sqlDa.UpdateCommand = sqlUpdateCommand1;
sqlDa.InsertCommand = sqlInsertCommand1;
sqlDa.DeleteCommand = sqlDeleteCommand1;
System.Data.SqlClient.SqlTransaction myTran = conn.BeginTransaction();
sqlUpdateCommand1.Transaction = myTran;
sqlInsertCommand1.Transaction = myTran;
sqlDeleteCommand1.Transaction = myTran;
try
{
sqlDa.Update(dt,xTableName);
myTran.Commit();
return true;
}
catch(System.Data.SqlClient.SqlException ex)
{
myTran.Rollback();
return false;
}
finally
{
conn.Close();
}
}