Kraxed
Kraxed

Reputation: 350

VB.NET: Load data from a MySQL database into a DataGridView control

I want to put the information from my MySQL database to a DataGridView(DataGridView1).

My "MySQL" Columns are

ID, Username & Password

The connection string is

"server=localhost;user id=root;password=;database=exdb"

The table in my database(exdb) is "users" and I have all the necessary connectors, MySQL imports & Re & references in my project.

What should I do?

Upvotes: 0

Views: 36318

Answers (1)

bonCodigo
bonCodigo

Reputation: 14361

Yes it's something you can search online and find an asnwer. Give this simple code a try:

System.Data;
System.Data.SqlClient

//create connection , replace userID/password if you have.
MySqlConnection con = 
  new MySqlConnection(@"server=localhost;user id=root;password=;database=exdb");     
con.Open();
//user the table name as per yours
MySqlDataAdapter adp = new MySqlDataAdapter("Select * from table1;" ,con);

DataSet ds = new DataSet();
adp.Fill(ds);
//change name according to your datagridview
dataGridView1.DataSource = ds;
dataGridView1.DataBind();

Upvotes: 1

Related Questions