我正在尝试使用localhost将我的应用程序与mysql服务器连接。我面临的问题超出了我的理解范围。我试过搜索它但找不到任何解决方案。
显示错误:
“不支持关键字:'uid'”;
以下是代码:
Form1.cs的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.CData.MySQL;
using MySql.Data.MySqlClient;
namespace DataAccess
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label4_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MySQLConnection connection;
String server = "localhost", database = "Student", userid = "root", password = "12345";
String connectionString = "SERVER = " + server + ";" + "DATABASE = " + database + ";" + "USERID =" + userid + ";" + "PASSWORD = " + password + ";";
String std_name = textBox1.Text, std_program = comboBox1.Text, std_department = comboBox2.Text;
int std_age = Convert.ToInt32(textBox2.Text);
// MySQLDataAdapter mda = new MySQLDataAdapter("Insert into student.registration(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)", connection);
connection = new MySQLConnection(connectionString);
MySQLCommand cmd;
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = "Insert into Student(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)";
cmd.ExecuteNonQuery();
MessageBox.Show("Record Successfully Entered!");
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
}
}