Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for records

Status
Not open for further replies.

brew2

Programmer
Joined
Apr 29, 2007
Messages
21
Location
US
Am slowly learning VB 2005. Tuf transition for me. Want to check if there is data in a db. Here is what I have so far:
Code:
Public Sub MTDatabase(ByRef bFound As Boolean)
        Dim dr As DataRow
        ds = New DataSet()
        cmd = New OleDbCommand("SELECT * FROM Members", cn)
        da.SelectCommand = cmd
        da.Fill(ds, "Members")
        Try
            For Each dr In ds.Tables("Members").Rows
                If dr.IsNull(1) Then
                    bFound = False
                Else
                    bFound = True
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        cn.Close()
    End Sub
This will go through each record when all that is needed is to find one. Also, if there is a blank record (more trouble) it will return false.

Appreciate any help.

Thanks.
 
So what is the question?

Christiaan Baes
Belgium

"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Is there a shorter/better/more efficient way of doing this?
 
yes, you can do "SELECT * FROM Members WHERE field1 IS NULL or where field2 IS NULL OR ..."

And then see if it returns more then 0 records.

Christiaan Baes
Belgium

"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top