【发布时间】:2023-04-07 15:24:02
【问题描述】:
好的,所以基本上我已经在 PhpMyAdmin 上制作了 MySQL 表。它在本地主机上,用户名 root,没有密码。
我正在开发基于 c# on visual express 2008 的 Windows 应用程序。我有以下代码用于保存/加载来自 MySQL 的数据的按钮(我已经按照一些链接/tuts 来达到这一点,但是不知道这在理论上如何连接到 MySQL @ phpmyadmin,我的意思是我不需要从 PhpmyAdmin 数据库下载文件并引用或将其作为插件添加到脚本中吗?完全迷失在这里..):
String connString = "SERVER = localhost; DATABASE = request; User ID = root; ID =; UserName =; Date =; Type =; Rules =;";
MySqlConnection mcon = new MySqlConnection(connString);
String command = "SELECT * FROM requesttcw";
MySqlCommand cmd = new MySqlCommand(command, mcon);
MySqlDataReader reader;
try
{
mcon.Open();
cmd.ExecuteNonQuery();
reader = cmd.ExecuteReader();
cmd.CommandType = System.Data.CommandType.Text;
while (reader.Read() != false)
{
Console.WriteLine(reader["ID"]);
Console.WriteLine(reader["ClanName"]);
Console.WriteLine(reader["Date"]);
Console.WriteLine(reader["Type"]);
Console.WriteLine(reader["Rules"]);
}
Console.ReadLine();
}
catch (Exception)
{
MessageBox.Show("ERROR: There was an error trying to connect to the DB!");
return;
}
cmd.CommandText = "INSERT INTO requesttcw (ClanName, Date, Type, Rules) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + richTextBox1.Text + "' LIMIT 1)";
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("You're Request Has Been Posted!");
}
catch (Exception ex)
{
string message = ("ERROR: There was an error submitting your form!" + ex + "");
DialogResult result = MessageBox.Show(message, "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
switch (result)
{
case DialogResult.Retry:
Application.Restart();
break;
case DialogResult.Cancel:
this.Close();
break;
}
}
当我运行它时,输入我的数据,然后单击按钮,它在线上给我这个错误(MySqlConnection mcon = new MySqlConnection(connString); * 不支持关键字。 参数名称:id *
请告诉我如何将它完全连接到 MySQL。我还下载了 MySQL 连接器并引用了 mysql.data.dll 文件。所以那部分也完成了......
【问题讨论】:
标签: c# mysql phpmyadmin