还有另一种方法可以在一个连接中保存多个数据。创建一个像这样的表
CREATE TYPE [dbo].[YourTypeName] AS TABLE(
[Col1] [bigint] NULL,
[Col2] [datetime] NULL,
[Col3] [bigint] NULL,
[Col4] [bigint] NULL,
[Col5] [datetime] NULL
)
然后写一个这样的程序....
CREATE PROCEDURE [dbo].YOURPROCEDURENAME]
(
@yourDataTableName YourTypeName READONLY
)
AS
INSERT INTO TableName
(Col1,
Col2,
Col3,
Col4,
Col5)
SELECT CP.Val1,
CP.Val2,
CP.Val3,
CP.Val4,
CP.Val15)
FROM @yourDataTableName CP
GO
然后在后面的代码中创建一个数据表,并像这样在程序中传递该数据表......
SqlCommand cmd = new SqlCommand("YOURPROCEDURENAME");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@yourDataTableName", SqlDbType.Structured).Value = datatable;
cmd.Parameters[0].TypeName = "YourTypeName ";