I'm a beginner developer and I'm currently learning Visual Basic 2008 Express Edition. I'd like create the following program:

  • search custom selected database
  • if selected database contains TABLEX and if TABLEX has data in ColumnY and it equals 0 then make some sort of signal/error/report where it's wrong and what should be changed

The code so far:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim sql As String ' SQL Command String
        Dim cmd As OleDb.OleDbCommand  ' New DB Command   

        Dim dbPath As String = OpenFileDialog1.FileName
        Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Data Source=" & dbPath & "; Persist Security Info = False;"

        Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(connStr)

        If dBaseConnection.State = 1 Then
            Label1.Text = "Database loaded!"
            Label1.Text = "Database not loaded!"
        End If

        sql = "SELECT ColumnY FROM TABLEX"

        cmd = New OleDb.OleDbCommand(sql, dBaseConnection)


    End Sub

How I can make the selected data equal a variable/string or anything like that? I just coudn't find any solution regarding this. And what if it has more similar data and I want to check each of them if it's 0?

Thanks for all the help and answers in advance!

Edited by number361

4 Years
Discussion Span
Last Post by Reverend Jim

MS Access 2000.

I'm basicly interested in the method of the whole thing.

  1. I select the table, column and row
  2. I make a check on the data
  3. Making decision based on result (read number, column for example: If table with two columns: Name, Apple. If John has zero apple the program will report that "database number 1, name: John has Zero apples)

That's what I'd like to do.


Pgamer: Er... No? I have only one database as "source", but it can be changed if I set a new. It's a simple "open new database button" and it sets as the new dbPath for the system and reopens it.

So basicly I have many DB and each of them has a "TABLEX".


My two cents - you try to open the database (lines 14-22) but you continue on and try the query even if the database doesn't open. If the open fails then you should not try the query.

Votes + Comments
Yeah, but what does a yellow light mean?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.