我有2个表,我想要的是当我单击第一个按钮时,第一个表将加载到Datagridview中,当我单击另一个第二个按钮时,它将加载另一个表。但问题是,我只会使用1个Datagridview。这可能吗?我不想使用其他Datagridview视图或其他表单。我想在1个表单中使用1个datagridview。下面是我加载到表的数据连接。我正在使用SQL Server。
Dim cn As New SqlConnection("Data Source=IT-ASSISTANT\sqlexpress;Initial Catalog=KIS;Integrated Security=True")
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim dt As New DataTable
表1:
cn.Open()
With cmd
.Connection = cn
.CommandText = "Select IDnumber as [ID Number], Productname as [Product
Name], Brand, UnitPrice as [Unit Price], Stocks, UnitType as
[Unit Type], ItemLocation as [Item Location], Remarks from
MainForm"
End With
dt.Clear()
With da
.SelectCommand = cmd
.Fill(dt)
End With
DGVdata.DataSource = dt
cn.Close()
End Sub
表2:
cn.Open()
With cmd
.Connection = cn
.CommandText = "Select IDnumber as [ID Number], itmDescription as [Item
Description], Supplier, UnitPrice as [Unit Price], Stocks,
nsnumber as [Next Number], itemLoc as [Item Location],
Remarks from FormsTable"
End With
dt.Clear()
With da
.SelectCommand = cmd
.Fill(dt)
End With
DGVdata.DataSource = dt
cn.Close()
End Sub