在visual studio中过滤访问表(2010)(2010年终极版) [英] filtering access tables (2010) in visual studio(2010 ultimate)

查看:74
本文介绍了在visual studio中过滤访问表(2010)(2010年终极版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已创建以下代码,并希望通过landlord_ID过滤我的数据库表。没有显示任何错误,当我调试它时似乎一切顺利(所有的landlord_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和访问数据库是在access2010上制作的)所以我不太了解所以会很感激那些更具体的答案。



感谢您阅读所有这些,希望您能帮助我



Hi, I have created the following code and want to filter my database table by landlord_ID. No errors have been shown and when I debug it all seems to go well (all the landlord_IDs come up with all the information e.g how many properties. However, when I double-click to select a certain ID nothing happens. If I add to part of the code like this : SQLString = "SELECT = FROM Flats WHERE landlord_ID = 1" ''& landlord_ID & ""
Then number 1 comes up but so do all the others (the rest should be filtered out).
Also, I have used this youtube link to help me: http://www.youtube.com/watch?v=4H2g8H0bqEg

Finally, This is my first time using visual studio (2010 Ultimate and the access databse was made on access2010) so I do not know much so would appreciate answers that are a little more specific.

Thank you for reading all of this and I hope you can help me

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

推荐答案

你没有做任何事情来帮助自己!你甚至没有读过我的回答(见我的评论)。



You did nothing to help yourself! You haven''t even read my past answer (see my comment).

Maciej Los写道:
Maciej Los wrote:

Suhail19,

(...)你需要做的是:

1)创建OleDbConnection [^],

2)使用方法Open()[^]方法打开它,

3)创建OleDbCommand [^]

4)设置CommandType [^],CommandText [^ ]属性,

5)创建OleDbDataReader [^]并调用ExecuteReader()[^]方法。

6)创建DataTable [^]和Load()[^]来自OleDbDataReader的数据。

7)将数据与组件绑定以显示数据(...)

Suhail19,
(...)what you need to do is:
1) Create OleDbConnection[^],
2) Open it using method Open()[^] method,
3) Create OleDbCommand[^]
4) Set CommandType[^], CommandText[^] properties,
5) Create OleDbDataReader[^] and call ExecuteReader()[^] method.
6) Create DataTable[^] and Load()[^] data from OleDbDataReader.
7) Bind data with your component to display data(...)





解决方案:



Solution:

Dim oConn As OleDbConnection = Nothing
Dim oComm As OleDbCommand = Nothing
Dim sConn As String = String.Empty
Dim sComm AS String = String.Empty
Dim oRdr As OleDbDataReader = Nothing
Dim oDt As Data.DataTable = Nothing
Try
    sConn = "specify connection"
    oConn = New OleDbConnection(sConn)
    oConn.Open()
    sComm = "SELECT * FROM Flats WHERE landlord_ID = " & lstLID.SelectedValue.ToString()
    oComm = New OleDbCommand(sComm, oConn)
    oRdr = oComm.ExecuteReader()
    oDt = New Data.DataTable("TableName")
    oDt.Load(ordr)
    grdFlats.DataSource=oDt
    oConn.Close()

Catch ex As Exception
   'show error 
Finally
   'clean up
End Try





直接从脑袋......未经测试!



Straight from a head... not tested!


这篇关于在visual studio中过滤访问表(2010)(2010年终极版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆