【问题标题】:filter Access 2010 database using Visual Studio 2010使用 Visual Studio 2010 过滤 Access 2010 数据库
【发布时间】:2013-04-10 20:37:14
【问题描述】:

我已经创建了以下代码,并希望通过房东 ID 过滤我的数据库表。没有显示任何错误,当我调试时一切似乎都很顺利(所有的地主 ID 都提供了所有信息,例如有多少属性)。

但是,当我双击选择某个 ID 时,没有任何反应。如果我像这样添加到部分代码中:

SQLString = "SELECT = FROM Flats WHERE landlord_ID = 1" '& landlord_ID & ""

然后数字 1 出现了,但所有其他的也出现了(其余的应该被过滤掉)。 另外,我使用了这个 YouTube 链接来帮助我:http://www.youtube.com/watch?v=4H2g8H0bqEg

最后,这是我第一次使用 Visual Studio(2010 Ultimate 和 Access 数据库是在 Access 2010 上制作的),所以我不太了解,所以希望得到更具体的答案。

感谢您阅读本文,希望您能帮到我

Imports System.Data.OleDb
Public Class Form1

   Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       OleDbDataAdapter2.Fill(DataSet11)
   End Sub

   Private Sub lstLID_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lstLID.SelectedIndexChanged
        Dim landlord_ID, SQLString As String
        Dim dtFlats As New DataTable()
        Dim dbDataAdapter As OleDbDataAdapter
        Dim ConnectString As String = "Provider= Microsoft.ACE.OLEDB.12.0;" & "Data Source = Database.accdb"
        landlord_ID = lstLID.Text
        SQLString = "SELECT = FROM Flats WHERE landlord_ID = " '& landlord_ID & ""
        dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectString)
        dbDataAdapter.Fill(dtFlats)
        grdFlats.DataSource = dtFlats
    End Sub
End Class

【问题讨论】:

    标签: visual-studio-2010 ms-access-2010


    【解决方案1】:

    我发现有两个问题

    SQLString = "SELECT = FROM Flats WHERE landlord_ID = " '& landlord_ID & ""
    
    1. SELECT = FROM 应该是SELECT * FROM

    2. WHERE landlord_ID = " '& landlord_ID & "" 如果撇号 ' 是 VB.NET 中的注释字符,那么它后面的所有内容都将被忽略。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-15
      • 2012-04-09
      • 1970-01-01
      相关资源
      最近更新 更多