0

我有存储过程,我想用它来获取我的 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();
4

1 回答 1

0

试试下面的。

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]);
            }
        }
于 2013-06-12T21:55:37.513 回答