Link to home
Start Free TrialLog in
Avatar of Rick
Rick

asked on

VB - Fill only specific DataGridView columns from db query

Hello,

I have the following DataGridView in my form:

| Assignment | Name | ID Number | Location |

I have a database query that will select the "Name" and "ID Number" from a table.
"Assignment" and "Location" will be entered manually.
Later I will have a button to export the data from the DataGridView to another database table.

My question is, how do I tell vb to fill only the "Name" and "ID Number" columns from my query?

I'm using VB 08.

Thank you,
Rick


dgViewText = "SELECT Name, ID_Number FROM tbl_emp"
 
data = New DataTable
 
adapter = New MySqlDataAdapter(dgViewText, conn)
 
CommandBuild = New MySqlCommandBuilder(adapter)
adapter.Fill(data)
dgView.DataSource = data

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ITHelper80
ITHelper80

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITHelper80
ITHelper80

Sorry this
Name.DataFeild = "ID_Number"
Name.HeaderText = "ID Number"
should be
ID.DataFeild = "ID_Number"
ID.HeaderText = "ID Number"