在C#中使用MySql数据库 [英] Using MySql DataBases with C#
本文介绍了在C#中使用MySql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好,所以我有一个包含7列的DataGridView,这些列的名称与MySql数据库和以下代码中的名称相同:
Ok, so I have a DataGridView with 7 columns, the column names are identical to the ones in my MySql Database and this code:
public partial class Form3 : Form
{
private MySqlConnection connection = new MySqlConnection();
private MySqlDataAdapter data = new MySqlDataAdapter();
public Form3()
{
InitializeComponent();
connection.ConnectionString =
"server=66.223.110.46;"
+ "database=blah blah;"
+ "uid=blah blah;"
+ "password=blah;";
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from data"; //table name
data.SelectCommand = command;
DataSet dataset = new DataSet();
data.Fill(dataset, "data"); //idk??
gridInfo.DataSource = dataset; //idk?
gridInfo.DataMember = "data"; //idk?
gridInfo.Dock = DockStyle.Fill;
}
基本上我想做的是从数据库中检索所有信息,并在DataGridView中显示它.希望您能帮帮我.
问候,
Melvin
Basically what I want to do is retreive all the info from the DataBase, and show it in the DataGridView. I hope you can help me.
Regards,
Melvin
推荐答案
Melvin,
写
hi Melvin,
write
gridInfo.DataBind();
代替
instead of
<pre lang="midl">gridInfo.DataMember = "data"; //idk?
gridInfo.Dock = DockStyle.Fill;
并且DataGridView的属性"DataFeild"设置为.aspx页中数据库中的相同名称
例如:(.aspx)
and DataGridView has property "DataFeild" set to ur colunm name same in database in .aspx page
for example : (.aspx)
<asp:GridView ID="gridInfo" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField DataField="Colunm_Name1" />
<asp:BoundField DataField="Colunm_Name2" />
<asp:BoundField DataField="Colunm_Name3" />
<asp:BoundField DataField="Colunm_Name4" />
</Columns>
</asp:GridView>
问候,
Gargi
Regards,
Gargi
我希望在程序中显示信息,并将数据库存储在远程服务器上,所以我并没有真正计划使用任何Web文件(.aspx)
I want the info displayed within the program, and have the database on a remote server, so I wasn''t really planning on using any webfiles (.aspx)
这篇关于在C#中使用MySql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文