扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年11月4日
关键字:
ArrayList ids = new ArrayList(); ArrayList qtys = new ArrayList(); string connectionString = "Data Source=MEDIACENTER;" + "Initial Catalog=AdventureWorks;Integrated Security=SSPI;" + "MultipleActiveResultSets=False"; string strSQLGetOrder = "Select * from Sales.SalesOrderDetail" + "WHERE SalesOrderID = 43659"; SqlConnection readConnection = new SqlConnection(connectionString); readConnection.Open(); SqlCommand readCommand =new SqlCommand(strSQLGetOrder, readConnection); using (SqlDataReader rdr = readCommand.ExecuteReader()){ while (rdr.Read()){ ids.Add(rdr["ProductID"]); qtys.Add(rdr["OrderQty"]); } } readConnection.Close(); string strSQLUpdateInv = "UPDATE Production.ProductInventory " + "SET Quantity=Quantity-@amt WHERE (ProductID=@pid)"; SqlConnection writeConnection = new SqlConnection(connectionString); writeConnection.Open(); SqlCommand writeCommand = new SqlCommand(strSQLUpdateInv,writeConnection); writeCommand.Parameters.Add("@amt",SqlDbType.Int); writeCommand.Parameters.Add("@pid",SqlDbType.Int); for(int lp=0;lp<ids.Count;lp++){ writeCommand.Parameters["@amt"].Value=qtys[lp]; writeCommand.Parameters["@pid"].Value=ids[lp]; writeCommand.ExecuteNonQuery(); } writeConnection.Close(); |
string connectionString = "Data Source=MEDIACENTER;" + "Initial Catalog=AdventureWorks;Integrated Security=SSPI;" + "MultipleActiveResultSets=True"; string strSQLGetOrder = "Select * from Sales.SalesOrderDetail" + "WHERE SalesOrderID = 43659"; string strSQLUpdateInv = "UPDATE Production.ProductInventory " + "SET Quantity=Quantity-@amt WHERE (ProductID=@pid)"; SqlConnection marsConnection = new SqlConnection(connectionString); marsConnection.Open(); SqlCommand readCommand = new SqlCommand(strSQLGetOrder, marsConnection); SqlCommand writeCommand = new SqlCommand(strSQLUpdateInv, marsConnection); writeCommand.Parameters.Add("@amt", SqlDbType.Int); writeCommand.Parameters.Add("@pid", SqlDbType.Int); using (SqlDataReader rdr = readCommand.ExecuteReader()){ while (rdr.Read()){ writeCommand.Parameters["@amt"].Value = rdr["OrderQty"]; writeCommand.Parameters["@pid"].Value = rdr["ProductID"]; writeCommand.ExecuteNonQuery(); } } marsConnection.Close(); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者