|
-
Feb 2nd, 2004, 09:37 AM
#1
Thread Starter
Member
using multiple datareaders
hi, in my program i have 2 listboxes. i am reading data out of my db and want to use 2 queries. These 2 queries will then use a datareader to out their results into the listboxes(one box for each query)
i am having problmes in using another datareader. i have follwed the syntax as to the way i defined the 1st one but still no luck. Here is my code:
Private Sub BtnMonday_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMonday.Click
BtnMonday.Enabled = False
Dim MonCount As Integer
MonCount = 0
Dim schcount As Integer
schcount = 0
LblTitle.Text = "You have searched for data For a Monday And for the week " & TxtWeek.Text
Me.OleDbCommand1.CommandText = "Select * From Emp Where Week='" & TxtWeek.Text & "'AND AvMon=True"
Me.OleDbCommand1.Connection = OleDbConnection1
Me.OleDbCommand2.CommandText = "Select * From School Where DayOfWeek = Monday"
Me.OleDbCommand2.Connection = OleDbConnection1
'Me.OleDbConnection1.Open()
OleDbCommand1.Connection.Open()
OleDbDataReader1 = OleDbCommand1.ExecuteReader()
Do While OleDbDataReader1.Read()
MonCount = MonCount + 1
ListBox1.Items.Add(OleDbDataReader1("EmpID") & " " & _
OleDbDataReader1("EmpName") & " " & _
OleDbDataReader1("Week") & " " & _
OleDbDataReader1("AvMon") & " ")
Loop
LblCount.Text = "Found " & MonCount & " Records"
OleDbConnection1.Close()
OleDbCommand2.Connection.Open()
OleDbDataReader2 = OleDbCommand2.ExecuteReader()
Do While OleDbDataReader2.Read()
schcount = schcount + 1
ListBox2.Items.Add(OleDbDataReader2("SchoolID") & " " & _
OleDbDataReader2("SchoolName") & " " & _
OleDbDataReader2("DayOfWeek") & " " & _
OleDbDataReader2("NumOfCoaches") & " ")
Loop
OleDbConnection1.Close()
End Sub
i have the following definitions as well:
Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbCommand2 As System.Data.OleDb.OleDbCommand
Dim OleDbDataReader1 As System.Data.OleDb.OleDbDataReader
Dim OleDbDataReader2 As System.Data.OleDb.OleDbDataReader
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbCommand2 = New System.Data.OleDb.OleDbCommand
sorry for the layout of the post but i could get the code in the tags
any help would be greatly appreciated
thankyou
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|