Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlDataReader in a Data Class
Message
From
27/10/2004 05:43:58
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Web forms
Environment versions
Environment:
ASP.NET
OS:
Windows 2000 SP3
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
00954589
Message ID:
00954801
Views:
16
>I have a multi tiered application I am working on and want to know the following:
>
>Using C#, can you create procedure in your data class using a SqlDataReader? I want to fill a drop down list. This is easy to due with a DataSet. Can anyone give me or point me to an example of using a SqlDataReader in a data class?
>
>Thank you.
>
>Tom

IMHO it's also a correct way for static lists.
private void fillMyCombo()
{
  SqlConnection cn = new SqlConnection(
    "Persist Security Info=False;Integrated Security=SSPI;database=pubs;server=localhost");
  cn.Open() ;
  SqlDataReader rdr = new 
   SqlCommand("select * from authors",cn).ExecuteReader(CommandBehavior.CloseConnection);
  while (rdr.Read())
  {
    myCombo.Items.Add(String.Format("{0},{1}",rdr["au_fname"],rdr["au_lname"]));
  }
  cn.Close();
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform