如何将Mysql表加载到C#的DATAGRIDVIEW [英] How load Mysql table to DATAGRIDVIEW of C#

查看:207
本文介绍了如何将Mysql表加载到C#的DATAGRIDVIEW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!全部

我是C#beginner的学生。我想将mysql表加载到C#的 datagridview。请有人帮帮我!谢谢大家。

解决方案

1)创建与数据库的连接。

2)查询要显示的数据。

3)将数据绑定到您放在表单上的datagridview控件。

4)当此过程中的相关代码不起作用时,请询问该特定问题在这里,我们可以帮助你。


这里,以下应该有所帮助: C#教程 - 将DataGridView绑定到数据库 [ ^ ]


Hi


与mysql你需要在你的项目中添加mysql.data.dll

你可以从下载这个dll在这之后



之后使用 MySql.Data.MySqlClient添加命名空间

 ; 

MySqlConnection conn = new MySqlConnection(connectionstring);
MySqlCommand cmd = new MySqlCommand( 您的sql查询);
MySqlDataReader dr = cmd.ExecuteReader();

gridview1.datasource = dr;
gridview1.databind();





您的连接字符串将是这样的

<&的ConnectionStrings GT;
< add name =connectionstringconnectionstring =Data source = server; database = mydb; user id = root; password = 1234providername =MySql.Data.MySqlClient/>
< / connectionstrings>





如果您需要文档点击这里



我希望这会对你有所帮助.. ..


Hi! All
I am student of C# beginner. I want to load mysql table to datagridview of C#. Please someone help me ! Thanks you all.

解决方案

1) Create a connection to your database.
2) Query for the data you want to show.
3) Bind that data to a datagridview control that you have placed on your form.
4) When something code related in this process doesn't work, ask that specific question here so we can help you.


Here, following should help: C# Tutorial - Binding a DataGridView to a Database[^]


Hi
To communicate with mysql you need to add mysql.data.dll in your project
You can download this dll from Here

after that add the namespace

using MySql.Data.MySqlClient;

MySqlConnection conn = new MySqlConnection(connectionstring);
MySqlCommand cmd = new MySqlCommand("Your sql query");
MySqlDataReader dr=cmd.ExecuteReader();

gridview1.datasource=dr;
gridview1.databind();



your connection string will be like this

<connectionstrings>
		<add name="connectionstring" connectionstring="Data source=server;database=mydb;user id=root;password=1234" providername="MySql.Data.MySqlClient" />
	</connectionstrings>



If you need documentation Click Here

I hope this will help you....


这篇关于如何将Mysql表加载到C#的DATAGRIDVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆