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我已經設法使先前的訂單部分正常工作。
編輯的一切都很好,但我想要一些迴應,即使只是爲了告訴我我很愚蠢...... –
爲什麼不製作查詢命令的字符串,然後在文本框中顯示該字符串? – Werdna