Bahatmut
Active member
Ok, all the help I've gotten ehre has been of tremendous aide to me. This one I thought would work, but I think I'm goofing someplace, and I can't wrap my head around datagrids enough yet to even attempt them, doubly since I'm just looking for display. The aim is to pull a range of records from one table, then pull a second range of records for each of the items in the first table. Below is the code I am using. I get an error when the second data reader tries to execute. Please forgive all the concatinations, I do go back and remove them later on in the optimization portion of my processes.
[/color][/size]
VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] TitleName [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] TitleID [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] TitleCost [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Double
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] DateAcq [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Date
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] Trents [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] Tincome [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Double
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] WString [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] ConnectString [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\videobarn\videobarn.mdb;User Id=admin;Password=;"
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myConnection [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbConnection(ConnectString)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myIConnection [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbConnection(ConnectString)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] VideoQuery [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = "SELECT Ref, Title, Date_Added,Cost_Price from Videos WHERE Title LIKE " & "'" & TextBox1.Text & "%" & "'"
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] IncomeQuery [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = " Select Ref, Return_Status, Cost FROM Returned_Loans where Ref = " & "'" & TitleID & "'"
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] VideoCommand [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbCommand(VideoQuery, myConnection)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] IncomeCommand [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbCommand(IncomeQuery, myConnection)
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] VideoReader [/size][size=2][color=#0000ff]As[/color][/size][size=2] OleDbDataReader
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] IncomeReader [/size][size=2][color=#0000ff]As[/color][/size][size=2] OleDbDataReader
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] SDateAcq [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] SCost [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] STIncome [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] STrents [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
[/color][/size][size=2]myConnection.Open()
VideoReader = VideoCommand.ExecuteReader
TextBox2.Text = ""
[/size][size=2][color=#0000ff]While[/color][/size][size=2] VideoReader.Read
TitleID = VideoReader.GetString(0)
TitleID = TitleID.PadLeft(5, " ")
TitleName = VideoReader.GetString(1)
TitleName = TitleName.PadRight(50, " ")
DateAcq = [/size][size=2][color=#0000ff]CDate[/color][/size][size=2](VideoReader.GetDateTime(2))
SDateAcq = Microsoft.VisualBasic.Left([/size][size=2][color=#0000ff]CStr[/color][/size][size=2](DateAcq), 10)
TitleCost = VideoReader.GetDouble(3)
SCost = [/size][size=2][color=#0000ff]CStr[/color][/size][size=2](TitleCost)
SCost = SCost.PadLeft(7, " ")
IncomeReader = IncomeCommand.ExecuteReader
[/size][size=2][color=#0000ff]While[/color][/size][size=2] IncomeReader.Read
Tincome = Tincome + IncomeReader.GetDouble(2)
[/size][size=2][color=#0000ff]If[/color][/size][size=2][color=#0000ff]Not[/color][/size][size=2] IncomeReader.IsDBNull(1) [/size][size=2][color=#0000ff]Then
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] StrComp(IncomeReader.GetString(1), "-", CompareMethod.Text) [/size][size=2][color=#0000ff]Then
[/color][/size][size=2]Trents = Trents + 1
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]While
[/color][/size][size=2]STIncome = [/size][size=2][color=#0000ff]CStr[/color][/size][size=2](Tincome)
STIncome = STIncome.PadLeft(6, " ")
STrents = [/size][size=2][color=#0000ff]CStr[/color][/size][size=2](Trents)
STrents = STrents.PadLeft(4, " ")
WString = TitleID & " " & TitleName & " " & SCost & " " & SDateAcq & " " & STrents & " " & STIncome
TextBox2.Text = TextBox2.Text & WString
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]While
[/color][/size][size=2]VideoReader.Close()
IncomeReader.Close()
myConnection.Close()
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
[size=2][color=#0000ff]
Last edited by a moderator: