0

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?

1

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Your importing SqlClient while using MysqlConnection, is that okay?
you imported System.Data; System.Data.SqlClient But you're using Mysql connection, is there no error with that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.