Get recordset from a stored procedure

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

I have a stored procedure that SELECTs records that match certain
restriction:

CREATE PROCEDURE dbo.algo_get_longterm_limits
(
@date AS DateTime
)
AS

SELECT asof_date, sec_id, shares, price, trade
FROM dbo.algo_longterm_limit
WHERE asof_date = @date

In my C#.NET code, how can I stored the recordset from running this
stored procedure into an ArrayList? Currently I have code as below
which does not catch the recordset:

DateTime dt = DateTime.Parse(day);

IDbCommand command = mConn.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText =
"db_dynamic_trading.dbo.algo_get_longterm_limits";
command.Parameters.Add(new SqlParameter("@date",
day));
command.ExecuteNonQuery();

Any advice on how to stored the recordset into some variable such as
ArrayList in C#.NET?

Thanks!
 
I HIGHLY recommend using a typed dataset. There's MUCH less coding
and much less potential for error, plus you get intellisense on your
tables and fields, your fields are type safe (an int is an int, a
string is a string, a uniqueidentifier is a Guid, etc...), it's almost
impossible to make a typo on table names, field names, view names,
stored procedure names, parameter names,... the compiler catches many
of your errors before you publish (even the editor will catch many
of'em), your queries are methods that take .NET typed parameters, and
so are your stored procedures, you don't have to manually code all of
your parameters, there's no SQL code in strings scattered throughout
your code (which also helps eliminate the potential for sql
injection), all your queries are in one place and attached to the
DataTable object that receives their results (visually, in the dataset
designer and logically in the classes they produce), you can drag and
drop tables, views, and stored procedures directly from your database
onto your DataSet design surface in Visual Studio... It's just LOADS
better and also solves your problem below. You can just drag and drop
your stored procedure from your database onto your DataSet design
surface, then you can just make a simple method call to execute the
thing. The result will be in a fully typed DataTable, which is also
compatible with all of the .NET list components (ListBox,
DataGridView, ComboBox, CheckBoxList, etc...) by pointing your visual
component's DataSource property to the DataTable. There are lots of
other benefits as well.

Hope that helps!
 
Back
Top