我想允许用户在数据库中查询特定的customer_id
并使用此选项用表中的用户相关信息填充textboxes(tbFName, tbLName, tbPhoneNum, etc)
,然后可以在另一个按钮上编辑,更新数据库。下面是我当前代码的副本和我正在尝试创建的表单的图像。
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
仅供参考我已经设法让以前的订单部分正常运作。
答案 0 :(得分:0)
您可以运行单独的查询以根据客户ID检索客户信息,并使用结果填充表单。然后运行查询以获取订单信息并填充DataGridView。