再会。我正在尝试制作一个注册页面并将信息存储在数据库中。我使用 Microsoft Access 制作了数据库。我得到:
INSERT INTO 语句中的语法错误
每次我按下“注册”按钮。我已经尝试在网上搜索类似的问题,并找到了一些类似“保留词”和“它必须是你的间距”的东西。我做了那些,它仍然给我错误。我错过了什么吗?
这是代码:
public void InsertRecord()
{
OleDbCommand cmd = new OleDbCommand("INSERT INTO ElemData(StudentID, [Password], [Name], Age, Birthday, Address, FatherName, MotherName, " +
"GuardianName, Class, Section, Email, PhoneNumber, MobileNumber) " +
"VALUES (@studentid, @password, @name, @age, @birth, @address, @father, @mother, @guardian, @classs, @section, @email, @phone, @mobile)", DBConnection.myCon);
cmd.Parameters.Add("@studentid", OleDbType.VarChar).Value = Studentid;
cmd.Parameters.Add("@password", OleDbType.VarChar).Value = Password;
cmd.Parameters.Add("@name", OleDbType.VarChar).Value = Name;
cmd.Parameters.Add("@age", OleDbType.VarChar).Value = Age;
cmd.Parameters.Add("@birth", OleDbType.VarChar).Value = Birth;
cmd.Parameters.Add("@address", OleDbType.VarChar).Value = Address;
cmd.Parameters.Add("@father", OleDbType.VarChar).Value = Father;
cmd.Parameters.Add("@mother", OleDbType.VarChar).Value = Mother;
cmd.Parameters.Add("@guardian", OleDbType.VarChar).Value = Guardian;
cmd.Parameters.Add("@classs", OleDbType.VarChar).Value = Classs;
cmd.Parameters.Add("@section", OleDbType.VarChar).Value = Section;
cmd.Parameters.Add("@email", OleDbType.VarChar).Value = Email;
cmd.Parameters.Add("@phone", OleDbType.VarChar).Value = Phone;
cmd.Parameters.Add("@mobile", OleDbType.VarChar).Value = Mobile;
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
DBConnection.myCon.Open();
cmd.ExecuteNonQuery();
DBConnection.myCon.Close();
}