473,419 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Question about datareaders... vs2005

Ian
I wish to use a datareader to loop through the result set of a stored
procedure. (Several resultsets actually.)

It's for rendering HTML, so I don't need to ever keep this data, just
stream through it.

If I create a dataset, I can create a queryadapter, and then add
sprocs. It will only let me create that sproc as a return a value
(which I guess is the old RETURN_VALUE param) or return nothing.

It won't let me return a datareader.

If I create a sproc as the select statement as a table adapter, it
won't let me return anything other than a table, or a filltable. I
can't get at the datareader there either.

Further, if I add to the class via the partial class mechanism, I can't
see the _commandcollection object.

Any ideas?

Nov 23 '05 #1
3 2137

Why not just execute the SP and then read back the results with the data
reader? You are just streaming through it after all, so no need for any of
these fancy .NET components.

Dim DataReader As SqlDataReader

' Guard.

Try

Dim Command As New SqlCommand

Command.Connection = m_Connection
Command.CommandText = "myStoredProcedure"
Command.CommandType = CommandType.StoredProcedure

Command.Parameters.Add("@some_parameter", SqlDbType.NText).Value =
some_parameter.value
Command.Parameters("@some_parameter").Direction =
ParameterDirection.Input

DataReader = Command.ExecuteReader()

If DataReader.HasRows = True Then

While DataReader.Read()

End While

End If

Catch sqlEx As SqlException

Finally

If Not DataReader Is Nothing Then
DataReader.Close()
End If

End Try


"Ian" <dr*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I wish to use a datareader to loop through the result set of a stored
procedure. (Several resultsets actually.)

It's for rendering HTML, so I don't need to ever keep this data, just
stream through it.

If I create a dataset, I can create a queryadapter, and then add
sprocs. It will only let me create that sproc as a return a value
(which I guess is the old RETURN_VALUE param) or return nothing.

It won't let me return a datareader.

If I create a sproc as the select statement as a table adapter, it
won't let me return anything other than a table, or a filltable. I
can't get at the datareader there either.

Further, if I add to the class via the partial class mechanism, I can't
see the _commandcollection object.

Any ideas?

Nov 23 '05 #2
Ian
Skip that rubbish I just wrote. I was trying to view the adapter's
internals from code which was actually the partial dataset class.

If you include
Namespace AdapterName
partial public class usbdoittableadapter
... then you can add a property which returns a datareader.

Nov 23 '05 #3
Ian

Robin Tucker wrote:
Why not just execute the SP and then read back the results with the data
reader? You are just streaming through it after all, so no need for any of
these fancy .NET components.

Oh I can do this no problem, but I spend my life these days assessing
new bits of code, so junior programmers can do it without typing
anything.

Dragging a sproc onto a form used to write all the parameters for you.
Some sprocs may have thirty parameters.

I love the way the sproc calling now just looks like a class
invocation, but to complete the picture it would have been brilliant
had it been implemented as an executereader via iterator as well,
instead of just being executenoquery and executescalar...

Eg,
dim myClass as new myDataset.MyQueryAdapter.

For each datarow as DataRow in myClass.mySproc.(Param1, Param2,
Param3).... ' execute reader call

This way, all the working out of how to set the thing up would have
been automated.

My reasons for doing this is to stop devs wasting a week writing code
to set up the parameters etc.

This may be actually possible, I just haven't found it yet.

Regards,
Ian

(ps Thanks for your answer anyway.)

Dim DataReader As SqlDataReader

' Guard.

Try

Dim Command As New SqlCommand

Command.Connection = m_Connection
Command.CommandText = "myStoredProcedure"
Command.CommandType = CommandType.StoredProcedure

Command.Parameters.Add("@some_parameter", SqlDbType.NText).Value =
some_parameter.value
Command.Parameters("@some_parameter").Direction =
ParameterDirection.Input

DataReader = Command.ExecuteReader()

If DataReader.HasRows = True Then

While DataReader.Read()

End While

End If

Catch sqlEx As SqlException

Finally

If Not DataReader Is Nothing Then
DataReader.Close()
End If

End Try


"Ian" <dr*****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I wish to use a datareader to loop through the result set of a stored
procedure. (Several resultsets actually.)

It's for rendering HTML, so I don't need to ever keep this data, just
stream through it.

If I create a dataset, I can create a queryadapter, and then add
sprocs. It will only let me create that sproc as a return a value
(which I guess is the old RETURN_VALUE param) or return nothing.

It won't let me return a datareader.

If I create a sproc as the select statement as a table adapter, it
won't let me return anything other than a table, or a filltable. I
can't get at the datareader there either.

Further, if I add to the class via the partial class mechanism, I can't
see the _commandcollection object.

Any ideas?


Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: yurps | last post by:
Hello, I want to create business and data access layer for my website. I am not sure what the right way to go is, I could use a code-generation tool, but want to understand a bit more about...
6
by: Ravikanth[MVP] | last post by:
Hi Alternative is check before assigning as TextBox value. TextBox1.Text =myRow==DBNull.Value)?"": (string)myRow HTH Ravikanth
1
by: VB Programmer | last post by:
I usually put my declarations for db connections, datasets, datareaders, etc... above the Try portion. Inside the Try is where I open my connection, executereader, etc... In the Catch portion I...
7
by: Guadala Harry | last post by:
I'm trying to design all of my data access logic into one centralized assembly. I'm wondering how to implement DataReaders. There's plenty of documentation on passing DataSets to the client from...
4
by: Griff | last post by:
The MSDN article: Developing high-performance ASP.NET applications recommends using the SqlDataReader above using DataSets. One of the advantage of using DataSets over DataReaders is (as I...
5
by: Ryan Ternier | last post by:
I know how this should be done in regards to nTier, but it seems a bit inneficient, and was wondering if there's a solution that I havn't thought of yet. (I'm switching this loop to For Each Row...
14
by: Steve | last post by:
Sorry in advance for my ignorance. Any help would sure be appreciated. I'm writing a fairly simple application with VB.Net and am obviously a bit of a newbie. This application will be used by 1,...
2
by: Mat | last post by:
Can i close Datareader before starting reading data? The connection is used(shared) by many events, which may occurs concurrently. But i read that the connection can't be used if data reader is...
1
by: Steve | last post by:
Hi, I currently display all the data on a website using tableadaptors and objectdatasources. Would it be significantly faster if I was to display the data by writing the code for a datareader...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.