C# 如何从 Windows 窗体连接到 MySQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1101961/
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
How can I connect to MySQL from windows forms?
提问by srinivas
How can I connect to a MySQL database from Windows Forms?
如何从 Windows 窗体连接到 MySQL 数据库?
采纳答案by hadi teo
Numerous sample of connection strings here : http://www.connectionstrings.com/
此处有大量连接字符串示例:http: //www.connectionstrings.com/
回答by Xn0vv3r
Use the Connector from here. There's a documentationtoo.
回答by Binoj Antony
Hereis a full article on connecting to mysql using Connector/Net 6.0.
这是关于使用Connector/Net 6.0连接到 mysql 的完整文章。
Alternatively you can also use OleDb to connect to MySql.
或者,您也可以使用OleDb 连接到 MySql。
回答by srinivas
private void button1_Click(object sender, System.EventArgs e)
{
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();
}
i think this gonna be the simple one right!!! but thanx all of u guys for responding and providing me the documentation!
我认为这将是最简单的一个!!!!但是谢谢你们所有人的回应并向我提供文档!