使用 MS-Access 在 VB.Net 中从数据集到文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22032185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:54:13  来源:igfitidea点击:

From Data Set to Textbox in VB.Net using MS-Access

vb.netms-accessdataset

提问by user3148632

Private Function Gelobee() As DataSet
    Dim connection As OleDb.OleDbConnection = New OleDbConnection
    connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=CMP.accdb"
    connection.Open()
    Dim da As OleDb.OleDbDataAdapter = New OleDbDataAdapter("SELECT IDDesc FROM [ItemDesc] WHERE " & PartNoTxt.Text & " ORDER BY IDID;", connection)
    Dim ds As New DataSet
    da.Fill(ds, "FilteredDesc")
    Return ds
    connection.Dispose()
    connection = Nothing
    DescTxt.Text = ds.Tables(0).Rows(1).Item(1)
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Gelobee()
End Sub

I am trying to get the result of the query in Function Gelobee to go to DescTxt.Text when I click the Button1. When I click the Button1, nothing appears in the DescTxt. No errors but It wont show the result in the textbox.

当我单击 Button1 时,我试图将 Function Gelobee 中的查询结果转到 DescTxt.Text。当我单击 Button1 时,DescTxt 中什么也没有出现。没有错误,但它不会在文本框中显示结果。

回答by Adam Zuckerman

Your code stops at the Returnstatement.

您的代码在Return语句处停止。

Change Gelobee() to this:

将 Gelobee() 更改为:

Private Function Gelobee() As DataSet
    ... ' Removed for brevity

    da.Fill(ds, "FilteredDesc")
    connection.Dispose()
    connection = Nothing
    DescTxt.Text = ds.Tables(0).Rows(1).Item(1)
    Return ds
End Function