2013-02-20 52 views
0

我有我需要使用urno搜索的VB.net項目,它應該填充所有文本框和組合框中的信息在表單上,​​它是從哪個數據存儲在database.here相同的形式是碼如何在vb.net中搜索和使用查詢填充文本框和組合框中的信息

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 

任何想法如何實現這一對此頗爲谷歌搜索did'nt於事無補....

+0

分解。您需要開始用查詢結果填充數據集。這是非常可googleable。 – Constanta 2013-02-20 15:02:15

+0

我知道如何填充數據集,只是不知道如何在字段中填充數據.... – CrashOverride 2013-02-20 15:35:50

+0

您需要使用ExecuteReader方法返回的數據讀取器來自己讀取返回的行,或者您需要創建一個數據適配器,讓它爲您讀取行並填充數據集。你試圖用哪種方式去使用它?看起來你現在有兩種方法的混合。 – 2013-02-20 15:36:18

回答

0

找到了一種方法來做到這一點,它的工作就像一個魅力.....

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