datareader??

jnash

Well-known member
Joined
Oct 20, 2006
Messages
111
Programming Experience
Beginner
im trying to get the values out of my Access database, it finds the correct rows in the database (that contain the project name) but it says all the values are empty (dbnull = true) , where they are not! any ideas
thanks , the values i want are strings !


VB.NET:
Private Sub formload()
        Dim order As String
        Dim fon As String
        Dim pn As String

        pn = InputBox("insert projectname top load")
        conn.Open()
        Dim strSQL As String = "SELECT * FROM form WHERE projectName = '" & pn & "'"
        Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, conn)
        Dim objReader As System.Data.OleDb.OleDbDataReader
        objReader = objCommand.ExecuteReader
        If (conn.State = ConnectionState.Open And objReader.HasRows) Then

            While objReader.Read

                If objReader.IsDBNull(3) And objReader.IsDBNull(4) = False Then

                    order = objReader.GetString(3)
                    fon = objReader.GetString(4)
                    MsgBox(fon)
                Else

                    MsgBox("row is null")

                End If

            End While

        Else

            MsgBox("no such project")

        End If
        conn.Close()
        objReader.Close()
        objReader = Nothing
        objCommand.Dispose()
    End Sub
 
Your logic is wrong....
You've told it to see if item 3 is null ..... and item is not null..... so if both are filled in, or even if just item 3 is filled in, you get your messagebox.

What you really want is this:
VB.NET:
If Not (objReader.IsDBNull(3) And objReader.IsDBNull(4)) Then

-tg
 
Back
Top