使用存储过程访问列表
本文关键字:列表 访问 存储过程 | 更新日期: 2023-09-27 18:18:01
我有一个存储过程,我想用它来获取c#类中的记录列表。
Stored procedure is
ALTER Procedure [dbo].[testing]
as
Begin
DECLARE @p66 DateTime2 = '2013-04-4 00:00:00.0000000'
DECLARE @p1 Int = 9
SELECT [t0].[cDate] AS [CDate], [t0].[nDate] AS [NDate], [t0].[eNum] AS [ENumber], [t0].[sId] AS [SId], [t0].[sId] AS [SId]
FROM [t_elist] AS [t0]
WHERE ([t0].[neDate] = @p0) AND ([t0].[eNum] <= @p99)
我如何调用这个存储过程来返回我c#代码中所有记录的列表?
After creating connection, sql command etc. Should I?
cmd.parameter.Add(storedprocName);
var list=storedprocName();
尝试以下操作。
using (var conn = new SqlConnection("you connection string here"))
using (var command = new SqlCommand("[dbo].[testing] ", conn)
{
CommandType = CommandType.StoredProcedure
})
{
SqlDataAdapter adapt = new SqlDataAdapter(command);
DataTable dt = new DataTable();
adapt.Fill(dt);
foreach (DataRow x in dt.Rows) {
Console.WriteLine("First column value : " + x[0]);
}
}