代码是这样的:
list转化成datatable (list中有100条记录):
public static DataTable Convert_Test(List<Test> lTest)
{
DataTable dtReturn = new DataTable();
dtReturn.Columns.Add(“id”);
dtReturn.Columns.Add(“detail”);
for (int i = 0; i < lTest.Count(); i++)
{
DataRow dr = dtReturn.NewRow();
dr[“id”] = lTest[i].id;
dr[“detail”] = lTest[i].detail;
}
}
存储过程调用:
sqlCon_price.Open();
SqlCommand sqlCom = new SqlCommand(“Table_Test”, sqlCon_price);
sqlCom.CommandType = CommandType.StoredProcedure;
SqlParameter sqlp = new SqlParameter(“@test”, dtData);
sqlp.TypeName = “new_Test”;
sqlp.SqlDbType = SqlDbType.Structured;
sqlCom.Parameters.Add(sqlp);
sqlCom.CommandTimeout = 3000;
sqlCom.CommandType = CommandType.Text;
sqlCom.ExecuteNonQuery();
return true;
数据库中:自定义类型 new_Test:
USE [DataBase_Test]
GO
CREATE TYPE [dbo].[new_Test] AS TABLE(
[id] [int] ,
[detail] [nvarchar](2300)
)
GO
存储过程:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREAT PROCEDURE [dbo].[Table_Test]
(
@test as new_Test READONLY
)
AS
BEGIN
SET NOCOUNT ON;
declare @countt int
select @countt=COUNT(1) from @test
print @counttest
end
这个地方的 @countt 获取到的值为0 。 为什么?
list转化成datatable (list中有100条记录):
public static DataTable Convert_Test(List<Test> lTest)
{
DataTable dtReturn = new DataTable();
dtReturn.Columns.Add(“id”);
dtReturn.Columns.Add(“detail”);
for (int i = 0; i < lTest.Count(); i++)
{
DataRow dr = dtReturn.NewRow();
dr[“id”] = lTest[i].id;
dr[“detail”] = lTest[i].detail;
}
}
存储过程调用:
sqlCon_price.Open();
SqlCommand sqlCom = new SqlCommand(“Table_Test”, sqlCon_price);
sqlCom.CommandType = CommandType.StoredProcedure;
SqlParameter sqlp = new SqlParameter(“@test”, dtData);
sqlp.TypeName = “new_Test”;
sqlp.SqlDbType = SqlDbType.Structured;
sqlCom.Parameters.Add(sqlp);
sqlCom.CommandTimeout = 3000;
sqlCom.CommandType = CommandType.Text;
sqlCom.ExecuteNonQuery();
return true;
数据库中:自定义类型 new_Test:
USE [DataBase_Test]
GO
CREATE TYPE [dbo].[new_Test] AS TABLE(
[id] [int] ,
[detail] [nvarchar](2300)
)
GO
存储过程:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREAT PROCEDURE [dbo].[Table_Test]
(
@test as new_Test READONLY
)
AS
BEGIN
SET NOCOUNT ON;
declare @countt int
select @countt=COUNT(1) from @test
print @counttest
end
这个地方的 @countt 获取到的值为0 。 为什么?
解决方案
40
本人来了,收分。