本文介绍了使用Connector / NET编程创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用连接器/网络编程创建数据库?
How to create a database using connector/net programming? How come the following doesn't work?
string connStr = "server=localhost;user=root;port=3306;password=mysql;";
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand cmd;
string s0;
try
{
conn.Open();
s0 = "CREATE DATABASE IF NOT EXISTS `hello`;";
cmd = new MySqlCommand(s0, conn);
conn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
推荐答案
MySqlCommand。
You might want to execute the MySqlCommand. Now you just create one, but it doesn't execute your query.
请尝试以下操作:
conn.Open();
s0 = "CREATE DATABASE IF NOT EXISTS `hello`;";
cmd = new MySqlCommand(s0, conn);
cmd.ExecuteNonQuery();
conn.Close();
这篇关于使用Connector / NET编程创建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!