标签:
如果你需要向存储过程中传递一个table 那么就用到了表值类型
1.创建表值类型
CREATE TYPE [dbo].[StorePreSeparationAmount] AS TABLE( [preSeparationId] [int] NOT NULL, [preSeparationAmount] [decimal](18, 2) NOT NULL, [userCode] [varchar](20) NOT NULL ) GO
2.创建存储过程
CREATE PROC sp_preSeparationCommit ( @spsa StorePreSeparationAmount READONLY ) AS UPDATE ps SET ps.preSeparationAmount=spsa.preSeparationAmount, ps.updater=spsa.userCode, ps.updateTime=GETDATE() FROM dbo.wms_preSeparation ps INNER JOIN @spsa spsa ON ps.preSeparationId=spsa.preSeparationId
3.Ado.net 使用表值类型
public bool updatePreSeparationAmount(DataTable dtStorePreSeparationAmount) { string strSpName = @"sp_preSeparationCommit"; SqlParameter[] pars = { new SqlParameter("@spsa",SqlDbType.Structured), }; pars[0].Value = dtStorePreSeparationAmount; pars[0].TypeName = "StorePreSeparationAmount"; int num = DalBase.ExecuteNonQuery(CommandType.StoredProcedure, strSpName, pars); if (num > 0) { return true; } else { return false; } }
备注:table创建
DataTable dtStorePreSeparationAmount = new DataTable("dtStorePreSeparationAmount"); dtStorePreSeparationAmount.Columns.Add("preSeparationId", Type.GetType("System.Int32")); dtStorePreSeparationAmount.Columns.Add("preSeparationAmount", Type.GetType("System.Decimal")); dtStorePreSeparationAmount.Columns.Add("userCode", Type.GetType("System.String")); DataRow drNew = dtStorePreSeparationAmount.NewRow(); drNew["preSeparationId"] = nPreSeparationId; drNew["preSeparationAmount"] = dPreSeparationAmount; drNew["userCode"] = login.UserName; dtStorePreSeparationAmount.Rows.Add(drNew);
标签:
原文地址:http://www.cnblogs.com/caohuimingfa/p/5156627.html