views:

380

answers:

3

I am updating a web application and have decided to use SubSonic as it seems awesome and I want to learn it :) I'm trying to return a SQLDataReader from a method I already have and have done it like this

public SqlDataReader GetAllCarTypes_dr()
{
    return (SqlDataReader)new Query("tblCarType").ExecuteReader();
}

Just checking this is the correct way to do it? Or is there a better subsonic syntax like ExecuteSQLDataReader()?

+2  A: 

The way you have specified is one way you can do it. However, there is no ExecuteSQLDataReader() function because it is redundant.

Since SQLDataReader already implements the IDataReader interface, there's no point in creating a function specific to a SQLDataReader.

You may consider returning the interface in the same manner SubSonic does, for example:

public IDataReader GetAllCarTypes_dr()
{
    return new Query("tblCarType").ExecuteReader();
}

and performing the assignment in your logic:

SQLDataReader reader = GetAllCarTypes_dr();

I would consider this the best way to do it.

John Rasch
Awesome thanks :)
leen3o
A: 

Well, it compiles, right? Just Kidding.

This link gives a little more of an explanation about when to use which: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/a8ed157d-e93c-4a8d-83a4-78645614b4ac

Just make sure you are closing the reader (readers?) somewhere so they don't leave open connections hanging around.

ranomore
Thanks for the link :)
leen3o
A: 
private void CreateDynamicControls()
{


 panGvHolder.Controls.Clear();

 Query qry = Northwind.Product.CreateQuery();
 qry.Columns.AddRange(Northwind.Product.Schema.Columns);
 qry.WHERE("UnitPrice > 15").AND("UnitsInStock < 20 ");
 //WHERE("UnitPrice > 15").AND("UnitsInStock < 30 ");



 using (IDataReader rdr = qry.ExecuteReader())
 {
  Response.Write("<table>");
  while (rdr.Read())
  {
   Response.Write("<tr>");
   for (int i = 0; i < rdr.FieldCount; i++)
   {
    Response.Write("<td>");
    Response.Write(rdr[i].ToString() + " ");
    Response.Write("<td>");
   } //eof for 
   Response.Write("</br>");
   Response.Write("</tr>");
  }
  Response.Write("<table>");
 }
} //eof method
YordanGeorgiev