NeverendeR NeverendeR - 9 days ago 5
Vb.net Question

Vb.Net select tables

I am new in Vb.NET and I have a code here which I got from example, which select one table. What I want is I want to select another tABLe.. I just want to select another table other than users.. since I have a another form which binds/call another table.

How will I do it?

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


I got it by doing this...

dataSet = New DataSet
adapter.SelectCommand.CommandText = "select * from dtr"
adapter.Fill(dataSet)

Answer

You should be able to change the command text of your example query to match what you want to pull back. For example:

command.CommandText = "SELECT col1, col2 from newTable"