繁体   English   中英

如何在vb.net中搜索并使用查询在文本框和组合框中填充信息

[英]how to search in vb.net and populate info in text boxes and combo boxes using query

我有一个VB.net项目,我需要使用一个urno进行搜索,它应该在表单上的所有文本框和组合框中填充信息,并且它是将数据存储在数据库中的同一表单。编码

Public Class MBAUpdate
    Dim con As New OleDb.OleDbConnection()
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            'Dim da As OleDb.OleDbDataAdapter
            Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
            Me.con = New OleDb.OleDbConnection()
            con.ConnectionString = dbprovider
            con.Open()

            Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
            Dim sqlcommand As New OleDb.OleDbCommand(sqlquery, con)
            Dim ds As DataSet

            With sqlcommand
                .CommandText = sqlquery
                .Connection = con
                .ExecuteReader()
            End With

            ' MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
End Class

关于如何实现此目标的任何想法都无法进行有效的搜索。

找到了一种方法,并且像魅力一样运转.....

Public Class MBAUpdate
    Dim con As New OleDb.OleDbConnection

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            'Dim da As OleDb.OleDbDataAdapter
            Dim dbprovider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Taher\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\Database1.accdb;Persist Security Info=False;"
            Me.con = New OleDb.OleDbConnection
            Dim sqlquery As String = "SELECT * FROM MBA WHERE urno=" & CInt(txtb1.Text) & ";"
            Dim command As New OleDb.OleDbCommand(sqlquery, con)
            Dim reader As OleDb.OleDbDataReader
            con.ConnectionString = dbprovider
            con.Open()

            reader = command.ExecuteReader()
            reader.Read()

            txtName.Text = reader(1).ToString()
            txtFname.Text = reader(2).ToString()
            txtCAdd.Text = reader(3).ToString()
            txtPAdd.Text = reader(4).ToString()
            txtEid.Text = reader(5).ToString()
            cmbGender.Text = reader(6).ToString()
            txtMno.Text = reader(7).ToString()




            ' MsgBox("Record Added")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
End Class

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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