Problem with DB ToString

archer_coal

Well-known member
Joined
Apr 4, 2003
Messages
96
I have a bunch of labels on my form that i would like to populate with the first row of my database table.

Im running into problems with DBNull values or No value errors

i have a function that determines what label to use and it works fine, but getting the right data with no errors is makin me nuts.

this is a really rough code to see if what i want is even possible so forgive the crudeness :D
Code:
Dim mySelectQuery As String = "SELECT * FROM " & var_month & " Where id = 1"
        Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\20304aa1.mdb")
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        myConnection.Open()

        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()

        Dim first As Integer
        Dim i, ds As Integer
        Do While myReader.Read
            first = myReader("first")
            
        Loop
        For i = 0 To 30
            lblday_value = myReader(1)
            get_label(first).Text = lblday_value

           first = (first + 1)

        Next
A reader here may not be the solution. But i have no idea how else to loop through all the fields of the "row".
Notice the select statement grabs the row i need already. Static Binding is out too.
 
try this one
Code:
lblday_value = myReader(1).ToString

By the way; shouldnt it be
Code:
lblday_value = myReader(i).ToString
???
 
Code:
Dim myReader As System.Data.OleDb.OleDbDataReader
OleDbConnection2.Open()
myReader = myCommand.ExecuteReader()
Dim name1 as String
Dim tel as Integer
While myReader.Read()
           name1 = myReader.GetString(0)
            tel = myReader.GetValue(1)
End While
myReader.Close()
OleDbConnection2.Close()

Hope this code helps you.
 
re

I keep getting this error
No data exists for the row/column.
I know some of the fields are null but not all of them and certainly not the first field
 
RE

i figured it out
my for loop was outside of my DO While loop so the reader was NOT reading while i was trying to populate the labels.
 
Back
Top