[英]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. 我正在创建应该与Access数据库一起使用的VB.NET应用程序。 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. 我已经创建了Microsoft Access 2010数据库(.accdb)并将其导入到VB.NET中,并使其中一张表显示在我的表单上。 On form 1 I have a button which links to form 2, on which the database table is displayed. 在表单1上,我有一个链接到表单2的按钮,在该按钮上显示数据库表。
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. 我要执行的是生成某种IF
语句,以说是否未选中记录中的特定字段,然后将其显示在FORM 1的列表框中。
For example I have a filed called "started" and its data type is Yes/No
. 例如,我有一个名为“ started”的文件,其数据类型为Yes/No
When a particular record is not checked (empty check-box) I want it to display in a list box on form 1. 当未选中特定记录时(空复选框),我希望它显示在表格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. 表'Jobs'被突出显示为未声明(未声明'Jobs'。由于其保护级别,因此可能无法访问。)并且由于数据库已连接,我不知道如何执行此操作。
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 感谢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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.