469,898 Members | 1,744 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Multiple Select Statements in resultset

Hi,

I'm trying to use several select statements so that I don't need to call
the function several times. The next Result set always seems to read the
first select statement. I have the following:
Dim queryString As String = "SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Motivate'; SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Present'"

If (dataReader.Read = True) Then
Dim Part = dataReader("Part")
Response.Write("Part is "&Part)
dataReader.NextResult()
Response.Write("Part is "&Part)
End If

So, I always get the first statement where part=motivate. I don't want to
use a Do While because I'll be doing something different with each result
set. I've just simplified it in the above example.

Thanks so much.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
3 1924
Joe it is hard to see what your trying to do but if your trying to base one
query off another you might try setting up a DataRelation Collection with
multiple DataTable commands in a DataSet instead of building multiple
DataReaders or trying to join multiple tables within a Select Command. It
might be easier for you to handle your Data that way

"Joe via DotNetMonster.com" wrote:
Hi,

I'm trying to use several select statements so that I don't need to call
the function several times. The next Result set always seems to read the
first select statement. I have the following:
Dim queryString As String = "SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Motivate'; SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Present'"

If (dataReader.Read = True) Then
Dim Part = dataReader("Part")
Response.Write("Part is "&Part)
dataReader.NextResult()
Response.Write("Part is "&Part)
End If

So, I always get the first statement where part=motivate. I don't want to
use a Do While because I'll be doing something different with each result
set. I've just simplified it in the above example.

Thanks so much.

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
Joe,

Your sample below always would return the part in the first resultset.
After each datareader.NextResult() you would need to do
Part = dataReader("Part")
You probably also need the If (dataReader.Read = True) Then before the
Part = ...

Another alternative might be to UNION your SELCT statement so you just
have one resultset.

I hope that helps.

Mike Douglas

On Sat, 26 Mar 2005 18:03:24 GMT, "Joe via DotNetMonster.com"
<fo***@DotNetMonster.com> wrote:
Hi,

I'm trying to use several select statements so that I don't need to call
the function several times. The next Result set always seems to read the
first select statement. I have the following:
Dim queryString As String = "SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Motivate'; SELECT TOP 1 ([tblPage].[Part]), [tblPage].
[PageNumber] FROM [tblPage] WHERE ([tblPage].[LessonID] = @LessonID) AND
[tblPage].[Part]='Present'"

If (dataReader.Read = True) Then
Dim Part = dataReader("Part")
Response.Write("Part is "&Part)
dataReader.NextResult()
Response.Write("Part is "&Part)
End If

So, I always get the first statement where part=motivate. I don't want to
use a Do While because I'll be doing something different with each result
set. I've just simplified it in the above example.

Thanks so much.


Nov 19 '05 #3
Thanks for you help. I ended up using a DataView Object in the Dataset and
that seems to work.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ralph Freshour | last post: by
1 post views Thread by Peter Neumaier | last post: by
2 posts views Thread by Diego | last post: by
2 posts views Thread by =?Utf-8?B?VGVycnk=?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.