Re: Datareader, dataset, else?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can use a DataTable. A DataSet is simply a container for DataTable
objects. There is no rule that states a DataTable must exist inside of a
DataSet.

A DataTable is more closely analogous to a RecordSet from classic ADO.

A DataReader is most closely analogous to a Read-Only/Forward-Only Recordset
(IIRC "static recordset").

A DataSet can hold the equivalent of a full-blown relational database in
memory - complete with multiple tables related explicitly through
DataRelation objects within the DataSet.

You don't have to leave a connection open when you use a DataReader (it has
to be opened only while you're reading it). Upon opening it you can have it
automatically close the connection - like this:

SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
myConnection.Open();
SqlDataReader myReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
}
myReader.Close();
//Implicitly closes the connection because
CommandBehavior.CloseConnection was specified.

-HTH




"Patreek" <dont@xxxxxxx> wrote in message
news:%23rC6yHlvFHA.252@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I'm writing my first real asp.net app at my job, and I'd like opinions
> please. In my classic ASP apps that I've written, I'd often have separate
> files for retreiving data and returning the data to other pages that would
> call it. I'd return the data as arrays so that I wouldn't have to have my
> DB connections open all the time while the pages ran. Now in .net, it
> seems like I have to choose between using a SQldatareader or a dataset.
> From what I'm reading, I can see parallels between the sqldatareader and
> an classic connected recordset, whereas a dataset seems to be kind of like
> a disconnected recordset. But the dataset has lots of overhead.
>
> So, it seems as thought if I use a function to return a datareader, I have
> to leave the connection open. That seems sloppy as I'd wind up with
> something like.
>
> dataclass.Openconnection
> thedatagrid.datasource dataclass.functionThatReturnsDatareader
> thedatagrid.databind
> dataclass.Closeconnection
>
>
> I just feel that the open/close lines would get on my nerves after a
> while.
>
> I could use a dataset instead, but I'm scared to use that after what I've
> read about the unnecessary bloat. Does anyone have any examples of what
> you do that you think is nice and clean and still keeps your database code
> separate from your app?
>
> Thanks!!!
>


.



Relevant Pages

  • Re: Fastest db methods?
    ... side-effects, such as scalability issues (for example, a SqlDataReader is ... > Reading a recordset using SqlDataAdapter.Fill/ reading a ... recordset using SqlDataReader ?? ... and then send the actual resultset. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataReader - how to get record count without closing?
    ... Thanks -- unfortunately the DataReader is very limited -- I was hoping it ... would be close to Static recordset provided by DAO 3.6 (which is extremely ... wanna see accurate progress. ... could get some indication of progress from SQL Server 2000 -- any such ...
    (microsoft.public.dotnet.framework.adonet)
  • large SELECT with ORDER BY very slow (only in ado.net)
    ... So if I do it in DAO ... seconds to iterate through the recordset. ... using OLE DB data provider with Ms Access. ... DbCommand.ExecuteReadernot from iterating through the dataReader. ...
    (microsoft.public.dotnet.general)
  • Re: Access 2007 - Anyone having trouble with really large conversions?
    ... I have a fairly large app, ... program, which has added even more forms, queries and linked tables. ... get errors when opening a recordset for a linked table. ... So Access 2007 always seems to use Recordset2 objects for its forms and reports ...
    (comp.databases.ms-access)
  • Re: Using Access with MySQL and Stored Procedures as source to Forms and Reports
    ... and retrieval in sprocs / views. ... app with code. ... If I were to use a BE server for a web based application than I would ... recordset I use code to modify it. ...
    (comp.databases.ms-access)