sproc DataTable question

  • Thread starter Thread starter neverstill
  • Start date Start date
N

neverstill

Hi-

I was just preparing to use some of the Stored Procedures that I've been
working on for my asp.net application.

it appears that you can't get a DataTable or DataSet back from
SqlCommand.Execute(). Why? I can get a DataReader, but I don't want to
have the connection still open.

How do we execute a stored procedure and return DataTable or DataSet? This
must be a common question...


Thanks,
Steve
 
YOu can get a DataTable Dataset back from a DataAdapter.Fill . The reason
is that DataReaders are 'connected' objects, that is, once the connection is
closed they are useless. DataTables and Datasets gain most of their value
once the connection is closed, and the DataAdapter takes care of many things
for you.

If you really want to use a cmd.Execute and get a table, you could use a
DataReader to fill the datatable, that's what happens under the hood anyway,
although I don't think there's any great reason not to use da.Fill

HTH,

Bill
 
yes, Bill that does help. Thank you. I realized after writing my original
message that I was looking at things all wrong and that indeed, I could use
da.Fill()

Thanks for the response!
 
Back
Top