Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlDataReader in a Data Class
Message
From
27/10/2004 13:04:49
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/10/2004 12:23:25
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:
00954922
Views:
20
I see. I was on the DataReader's side as it's the piece under the hood used by DataAdapter to Fill() and provides fast forward readonly access.
Also probably this DataAccess class is some special class that I don't know.
DataAccessApplicationBlocks does similar to return an SqlReader object.
PS: Accept me as a newbie to C#,ADO.NET and ASP.NET:)
Cetin

>Cetin,
>
>I know ... that's why I said that DataReaders are a bit of a gray area. I personally have not used them. I use DataAdapters exclusively and return DataSets from my DataAccess class. But still, I think that by having the DataReader be public in the DataAccess class, it might be ok . Another option would be to have methods in the DataAccess class that simulate what you'd get with the DataReader.
>
>Others who have actually used DataReaders in this manner may have more to say on the matter, as it's all a bit theoretical from my standpoint. =)
>
>~~Bonnie
>
>
>>Well Bonnie,
>>What then if you send (or it gets from a stored place, appsetting etc) your dataclass sql + connection and it returns you the reader. Readers should have explicit connections anyway else they'd fail. Would that make it multiered?
>>Cetin
>>
>>
>>
>>>Cetin,
>>>
>>>>It only helps me to be confused understanding what a multitiered app is.
>>>>If this code is in a user control that a web page uses and data layer is SQL server I count it as multiple layers/tiers.

>>>
>>>Well, ok, I can see your confusion. But, IMHO, multi-tier doesn't mean simply separating the data itself, but also separating the data *access* and/or business layer. In your example, if that code is used on a web page then you are entirely tied into SQL Server for your data store. This may be a non-issue for you, but it still doesn't totally isolate your data access from your UI. Now, if you were to put the code in a separate DataAccess class and you suddenly needed to use Oracle for one of your customers instead of SQL Server, your UI (web page in your example) doesn't change at all. It will still call the same DataAccess class, you will have simply substituted a DataAccess class that utilizes Oracle instead of SQL Server.
>>>
>>>Another reason for doing this ... if you have a both WebForms and WinForms in your app, then you certainly wouldn't want to be duplicating the DataAccess in both places, you'd want a common DataAccess class to do this.
>>>
>>>Separating this stuff is a little difficult in the example that Tom was looking for because he's using a DataReader rather than a DataAdapter, which isn't as "cut-and-dried" (since the DataReader's connection remains open). But, still, Randy's suggestion (to just have the DataReaderr be public in the DataAccess class) is an acceptable way to handle that.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>I don't know, show me multitiered version of this so I can comment:)
>>>>Cetin
>>>>
>>>>
>>>>>Unfortunately, this isn't multi-tiered, Cetin, since you have your DataAccess directly in your UI. Tom was looking for a multi-tiered solution.
>>>>>
>>>>>~~Bonnie
>>>>>
>>>>>
>>>>>>>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