简体   繁体   English

VB.NET:将数据从MySQL数据库加载到DataGridView控件中

[英]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). 我想将信息从我的MySQL数据库放到DataGridView(DataGridView1)。

My "MySQL" Columns are 我的“ MySQL” 专栏

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. 我的数据库(exdb)中的表是"users" ,我在项目中拥有所有必需的连接器,MySQL导入和重新引用。

What should I do? 我该怎么办?

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM