我是 Vb.NET 的新手,我在这里有一个从示例中获得的代码,它选择一个表。我想要的是我想选择另一个表。我只想选择用户以外的另一个表。因为我有另一个绑定/调用另一个表的表单。
我将如何做?
Dim connection As MySql.Data.MySqlClient.MySqlConnection
Dim adapter As MySql.Data.MySqlClient.MySqlDataAdapter
Dim commandBldr As MySql.Data.MySqlClient.MySqlCommandBuilder
Dim command As MySql.Data.MySqlClient.MySqlCommand
Dim dataSet As System.Data.DataSet
Dim bindingSource1 As BindingSource
Private Sub btConnect_Click(sender As System.Object, e As System.EventArgs) Handles btConnect.Click
connection = New MySql.Data.MySqlClient.MySqlConnection
connection.ConnectionString = "user id=" & tbUserName.Text + "; password=" & tbPassword.Text & "; server=" & tbServer.Text & "; database=" & tbDatabase.Text & "; pooling=false;"
Try
connection.Open()
adapter = New MySql.Data.MySqlClient.MySqlDataAdapter
commandBldr = New MySql.Data.MySqlClient.MySqlCommandBuilder
command = New MySql.Data.MySqlClient.MySqlCommand
dataSet = New System.Data.DataSet
bindingSource1 = New BindingSource
commandBldr.DataAdapter = adapter
command.CommandText = "SELECT userID,pin, print1, print2 from users"
command.Connection = connection
adapter.SelectCommand = command
adapter.Fill(dataSet)
bindingSource1.DataSource = dataSet.Tables(0)
dgvUsers.DataSource = bindingSource1
Catch ex As Exception
End Try
我通过这样做得到它...
dataSet = New DataSet
adapter.SelectCommand.CommandText = "select * from dtr"
adapter.Fill(dataSet)