0

I have stored procedure that I want to use it to get a list of records in my c# class.

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)

How do I call this stored procedure to return me the list of all the records in my C# code?

After creating connection, sql command etc. Should I?
         cmd.parameter.Add(storedprocName);
         var list=storedprocName();
0

1 Answer 1

0

Try the following.

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]);
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.