mysql数据库与c#代码的连接 [英] mysql database connectivity to c# code

查看:86
本文介绍了mysql数据库与c#代码的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
我想在c#代码文件中使用mysql数据库的连接.
什么是连接字符串&安装Mysql

Hi
I want to use connection of mysql database in c# code file.
What will be the connection string & what setting do I need for that after installing Mysql

推荐答案

http:/之后,我需要什么设置/bitdaddys.com/MySQL-ConnectorNet.html [ ^ ]
从.NET应用程序连接到MySQL数据库. [ http://www.connectionstrings.com [
http://bitdaddys.com/MySQL-ConnectorNet.html[^]
Connecting to MySQL database from your .NET applications.[^]

For connection string, you can always refer to http://www.connectionstrings.com[^]


您执行的操作与Microsoft sql数据库相同,但要使用MySqlConnection,Command和阅读器.这是一个受欢迎的代码示例

You do it the same as you would a microsoft sql database, but use a MySqlConnection,Command, and reader. Here''s a popular code sample

<pre lang="c#">string MyConString = "SERVER=localhost;" +
        "DATABASE=mydatabase;" +
        "UID=testuser;" +
        "PASSWORD=testpassword;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select * from mycustomers";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
        string thisrow = "";
        for (int i= 0;i<reader.fieldcount;i++)>
                        thisrow+=Reader.GetValue(i).ToString() + ",";
        listBox1.Items.Add(thisrow);
}
connection.Close();


http://www.connectionstrings.com上查看各种连接字符串选项/mysql [ ^ ] for MySql.
Have a look at various connection string options at http://www.connectionstrings.com/mysql[^] for MySql.


这篇关于mysql数据库与c#代码的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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