473,400 Members | 2,145 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,400 software developers and data experts.

Using Readers for SQL queries in a loop, want to sort results in alphabetical VB.net

Ok heres my problem, I have a database which has a table in it that
has all the staff members who are currently signed out of hte office.
That has their staff ID, and the time they are out till etc, then
another database has the staff table in it, which matches the ID to
names.

I am trying to do a basic query for all people who are signed out at
the moment for a front page of our intranet. I've got that all sorted,
but I can only sort the results by StaffID (which is uselss) or Time
due back in, not by name like I want.

Here is my code so far:
conn.Open()
conn2.Open()

Dim SignedOutCommand As New SqlCommand("Select StaffID,
InTime, HaveMob FROM StaffOut ORDER BY InTime", conn)
Dim FirstName
Dim LastName
Dim x = 0

Dim loopcount = 0
Dim IDReader As SqlDataReader =
SignedOutCommand.ExecuteReader()
While IDReader.Read()
Dim InTime
Dim HaveMob
Dim InDate
Dim ComingIn

StaffID = IDReader.Item("StaffID")
ComingIn = IDReader.Item("InTime")
InDate = Left(ComingIn, 10)
InTime = Right(ComingIn, 11)

Dim NameCommand As New SqlCommand("Select FirstName,
LastName FROM Staff WHERE StaffID = '" & StaffID & "'", conn2)
Dim NameReader As SqlDataReader =
NameCommand.ExecuteReader()

While NameReader.Read()

FirstName = NameReader.Item("FirstName")
FirstName = ToTitleCase(FirstName)
LastName = NameReader.Item("LastName")
LastName = ToTitleCase(LastName)
If DateValue(InDate) DateValue(Now()) Then
NameLabel.Text &= "<tr><td>" & FirstName & " " &
LastName & "</td><td><Font color='blue'>" & InDate & "</font><br></
tr>"
ElseIf DateValue(InDate) = DateValue(Now) Then
If TimeValue(Now) TimeValue(InTime) Then

NameLabel.Text &= "<tr><td>" & FirstName & " "
& LastName & "</td><td><Font color='red'>" & InTime & "</font><br></
tr>"
Else
NameLabel.Text &= "<tr><td>" & FirstName & " "
& LastName & "</td><td>" & InTime & "<br></tr>"
End If
Else
NameLabel.Text &= "<tr><td><Font color='red'>" &
FirstName & " " & LastName & "</font></td><td><Font color='red'>" &
InTime & "</font><br></tr>"

End If

End While
NameReader.Close()
End While

IDReader.Close()

conn.Close()
conn2.Close()
NameLabel.Text &= "</table>"

with con and conn2 being my two connections for the different
databases.
As you can see it loops through all the people who are out, and for
each of these it does another sql query to find out their name, then
adds a row to the table in my namelable.text (I am using a user
control)

I'm just beginning with ASP.net, I know a bit of ASP and PHP, so the
most familiar way for me to interact with databases is as above, I
know there is all these different ways to but I dont know how to just
yet. If it is the only way to do things I will go and learn one of
those ways.

Apr 23 '07 #1
7 1575
<it******@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Ok heres my problem, I have a database which has a table in it that
has all the staff members who are currently signed out of hte office.
That has their staff ID, and the time they are out till etc, then
another database has the staff table in it, which matches the ID to
names.
Are these really two separate databases, as opposed to two separate
tables...?

If so, are they on the same server at least...?
Apr 23 '07 #2
Yes they are both on a SQL2000 server, One database is called Infobase
and was made years ago, and one is called WhereAreYou

Stupid that they are separated I know.

On Apr 23, 4:28 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
<itfet...@gmail.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...
Ok heres my problem, I have a database which has a table in it that
has all the staff members who are currently signed out of hte office.
That has their staff ID, and the time they are out till etc, then
another database has the staff table in it, which matches the ID to
names.

Are these really two separate databases, as opposed to two separate
tables...?

If so, are they on the same server at least...?

Apr 23 '07 #3
<it******@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Yes they are both on a SQL2000 server, One database is called Infobase
and was made years ago, and one is called WhereAreYou
OK.
Stupid that they are separated I know.
Indeed, but are both databases on the same server...?
Apr 23 '07 #4
On Apr 23, 4:45 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
<itfet...@gmail.comwrote in message

news:11**********************@n59g2000hsh.googlegr oups.com...
Yes they are both on a SQL2000 server, One database is called Infobase
and was made years ago, and one is called WhereAreYou

OK.
Stupid that they are separated I know.

Indeed, but are both databases on the same server...?
yep, both on the same machine, is there a way to query both databases
at the same time or something?

Apr 23 '07 #5
On Apr 23, 8:53 am, itfet...@gmail.com wrote:
yep, both on the same machine, is there a way to query both databases
at the same time or something?
SELECT ... FROM [database_name1].[dbo].[table1] T1, [database_name2].
[dbo].[table2] T2 WHERE...

Apr 23 '07 #6
<it******@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
>Indeed, but are both databases on the same server...?

yep, both on the same machine, is there a way to query both databases
at the same time or something?
Indeed there is! That's why I was asking...

From Database1:

SELECT * FROM Database2..MyTable WHERE...
Apr 23 '07 #7
legends! I'll give that a go.

Thanks heaps for all your help

Apr 23 '07 #8

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

Similar topics

2
by: d2r2 | last post by:
Hi, I'm trying to run a nested (UNION) query against a MSAccessXP database (version 2002; build 10.6501.6714; SP3) In Access the SQL-statement executes just fine. When I run it in a asp-page I...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
5
by: Martin Lacoste | last post by:
There's likely not a simple answer for this, I know, but, I thought I'd try anyways... Background.. I've been racking my brain with some queries that I thought were straightforward, but have...
12
by: Susan Bricker | last post by:
For those of you who have been following my posts - they all pertain to a Dog Competition Organization's Database. There are three classes that the dogs can participate: NOVICE, OPEN, and...
7
by: canteyn | last post by:
Here is my problem: Structure typedef struct { char lname; char fname; int age; double salary; } employee_t;
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
1
by: mosullivan | last post by:
I had to write a program that would accept 7 strings through scanf, list the strings, alphabetize, and relist. I was supposed to use strcmp to assist with the sort and write it so that it can sort...
4
by: JHite | last post by:
I am using Access 2003 on Windows XP. This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and...
14
by: xtheendx | last post by:
I am writing a gradbook type program. It first allows the user to enter the number of students they want to enter. then allows them to enter the first name, last name, and grade of each student. The...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.