简体   繁体   中英

Display unchecked records from an Access database in VB.NET

I am creating a VB.NET application that is supposed to work with my Access database. I have created and imported a Microsoft Access 2010 database (.accdb) into VB.NET and made one of the tables to display on my form. On form 1 I have a button which links to form 2, on which the database table is displayed.

What I want to do is generate some kind of IF statement to say if a particular field in a record is unchecked than display it in a list-box on FORM 1.

For example I have a filed called "started" and its data type is Yes/No . When a particular record is not checked (empty check-box) I want it to display in a list box on form 1.

Could someone advise me if this is possible and how I could go around doing this?

EDIT: After trying a few things out, here is what I have so far. The table 'Jobs' is being highlighted as not declared ('Jobs' is not declared. It may be inaccessible due to its protection level.) and I can't figure out how to do this, as the database is connected.

 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTostart.SelectedIndexChanged
    Dim Started, SQLString As String
    Dim ConnectString As String = "Provider = Microsoft.ACE.OLEDB.12.0;" & "Data Source = KNmidlands_db.accdb"
    SQLString = "SELECT *  FROM Jobs WHERE Started = 0"  '--> 1 = Yes / 0 = No
    If Jobs.Rows.Count > 0 Then

        For x As Integer = 0 To Jobs.Rows.Count - 1

            lstTostart.Items.Add(Jobs.Rows(x).Item("whatever"))

        Next

    End If
End Sub

Thanks Aleksander

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Me.OleDbDataAdapter1.Fill(Me.DataSet11.Jobs)
    Fill_List()
End Sub

Sub Fill_List()
    Dim ConnectString As String = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = kn.accdb"
    Dim con As New OleDbConnection(ConnectString)
    Dim da As OleDb.OleDbDataAdapter
    Dim dt As New DataTable

    con.Open()
    da = New OleDb.OleDbDataAdapter("SELECT *  FROM Jobs WHERE NOT Started = true", con)
    da.Fill(dt)

    MsgBox(Format(dt.Rows.Count))

    If dt.Rows.Count > 0 Then

        For x As Integer = 0 To dt.Rows.Count - 1

            ListBox1.Items.Add(dt.Rows(x).Item("Job ID"))

        Next

    End If
    con.Close()
End Sub

End Class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM