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.

Not working :/.

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.


    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

        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
            End If
        End While

    End Sub

Hope this points you in the right direction...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.