VB.NET:将数据从 MySQL 数据库加载到 DataGridView 控件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14475918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET: Load data from a MySQL database into a DataGridView control
提问by Kraxed
I want to put the information from my MySQL database to a DataGridView(DataGridView1).
我想将我的 MySQL 数据库中的信息放到 DataGridView(DataGridView1) 中。
My "MySQL" Columnsare
我的“MySQL”列是
ID, Username & Password
The connection stringis
该连接字符串是
"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 导入和 Re 引用。
What should I do?
我该怎么办?
回答by bonCodigo
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();