How can I retrieve a table from stored procedure to a datatable?

后端 未结 3 538
盖世英雄少女心
盖世英雄少女心 2020-12-05 04:26

I created a stored procedure so as to return me a table.

Something like this:

create procedure sp_returnTable
body of procedure
select * from table
e         


        
3条回答
  •  情话喂你
    2020-12-05 04:44

    Explaining if any one want to send some parameters while calling stored procedure as below,

    using (SqlConnection con = new SqlConnection(connetionString))
                {
                    using (var command = new SqlCommand(storedProcName, con))
                    {
                        foreach (var item in sqlParams)
                        {
                            item.Direction = ParameterDirection.Input;
                            item.DbType = DbType.String;
                            command.Parameters.Add(item);
                        }
                        command.CommandType = CommandType.StoredProcedure;
                        using (var adapter = new SqlDataAdapter(command))
                        {
                            adapter.Fill(dt);
                        }
                    }
                }
    

提交回复
热议问题