2016-07-14 75 views
0

我想允許用戶查詢數據庫中特定的customer_id ,並使用它來填充textboxes(tbFName, tbLName, tbPhoneNum, etc)與用戶表中的相關信息,然後可以在另一個按鈕上編輯按下更新數據庫。以下是我目前的代碼副本和我正在嘗試創建的表單的圖像。如何將SELECT查詢結果顯示在vb.net的文本框中

Public Class searchcustomers 

    Dim sql As New sqlcontrol 

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click 
     Me.Close() 
    End Sub 

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click 
     If sql.HasConnection = True Then 
      sql.RunQuery("SELECT order_id, date_ordered, order_total, collection_method, staff_id FROM orders WHERE customer_id=" & tbSearchID.Text & " ORDER BY date_ordered") 
      If sql.sqldataset.Tables.Count > 0 Then 
       dgvPOrders.DataSource = sql.sqldataset.Tables(0) 

      End If 
     End If 
     'queries database to search for customer id to then display relevant data in data grid view' 

    End Sub 

    Private Sub searchcustomers_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

    End Sub 

    Private Sub btnSearchName_Click(sender As Object, e As EventArgs) Handles btnSearchName.Click 
     If sql.HasConnection = True Then 
      sql.RunQuery("SELECT customers.customer_id, order_id, date_ordered, order_total, collection_method, staff_id FROM (customers INNER JOIN orders on orders.customer_id=customers.customer_id) WHERE customers.first_name=" & tbSearchFName.Text & "") 
      If sql.sqldataset.Tables.Count > 0 Then 
       dgvPOrders.DataSource = sql.sqldataset.Tables(0) 
      End If 
     End If 
     'queries database to search for customer name to then display relevant data in data grid view' 
    End Sub 
End Class 


FYI我已經設法使先前的訂單部分正常工作。

image of form

+0

編輯的一切都很好,但我想要一些迴應,即使只是爲了告訴我我很愚蠢...... –

+0

爲什麼不製作查詢命令的字符串,然後在文本框中顯示該字符串? – Werdna

回答

0

您可以運行單獨的查詢檢索基於客戶ID的客戶信息和使用結果來填充表單。然後運行查詢以獲取訂單信息並填充DataGridView。

相關問題