1,105,538 Community Members

Check if datacolumn has a value

Member Avatar
Jake.20
Junior Poster
124 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Greetings fellow developers,

can you guys give me a hint on how to check if the datacolumn or datarow on the database has a value or null value what i want to happen is if the column1 has a value then the button is disabled.

    Dim Str As String
    Str = "SELECT studentId ,quiz ,midterms ,finals FROM result WHERE studentId ='" & studentProfile.studentId.Text & "' "
    sqlCom = New SqlCommand(Str, getConnect)
    Dim sqlRdr As SqlDataReader
    sqlRdr = sqlCom.ExecuteReader()

this is my code and i'm stuck with it i used sqlRdr.HasRows but it didn't fixed the problem. I will really appriciate any related answers.

advance thank you.

Member Avatar
Unimportant
Posting Whiz in Training
267 posts since Oct 2010
Reputation Points: 18 [?]
Q&As Helped to Solve: 54 [?]
Skill Endorsements: 9 [?]
 
0
 
Member Avatar
Jake.20
Junior Poster
124 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Not working :/.

Member Avatar
kRod
Junior Poster
139 posts since May 2012
Reputation Points: 49 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 6 [?]
 
0
 

I'm working on a small database app to organize my song files and threw together this little sub to demonstrate a Null value in one of the columns of a record. It's OldeDB but should easily be adapted to SQL.

I purposely left the Album name out on one of the records and it worked as expected! Below are the Column Names.

ID  ALBUM   ARTIST  TITLE   RELEASED    LOCATION    BIT_RATE    [SIZE]  DURATION    GENRE




    Private Sub Search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim startUp As String = Environment.CurrentDirectory
        Dim conStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & startUp & "\MusicList.accdb;Persist Security Info=False;"

        Dim sql As String = "Select * From SONGS"
        Dim conn As New OleDb.OleDbConnection(conStr)

        Dim cmd As New OleDb.OleDbCommand()
        With cmd
            .CommandText = sql
            .CommandType = CommandType.Text
            .Connection = conn
        End With

        Dim rdr As OleDb.OleDbDataReader

        conn.Open()
        rdr = cmd.ExecuteReader
        While rdr.Read
            'Check if the Second Column is null
            'if so report the song name 
            'first column is AutoNumber "ID" Second Column is the "Album"
            If rdr.IsDBNull(1) Then 'Checking 2nd Column for null
                MsgBox(rdr.GetValue(3).ToString)
            End If
        End While

       conn.Close
    End Sub

Hope this points you in the right direction...

Question Answered as of 9 Months Ago by Unimportant and kRod
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article