问题描述
美好的一天.我正在尝试制作一个注册页面,并将信息存储在数据库中.我使用Microsoft Access制作了数据库.我得到:
Good day. I am trying to make a registration page and have the information stored in a database. I made the database using Microsoft Access. I get:
每次我按下注册"按钮.我已经尝试过在网上搜索类似的问题,并发现了一些类似保留字"和它必须是您的空格"之类的东西.我做了那些,它仍然给我错误.我想念什么吗?
every time I press the 'Register' button. I have already tried searching on the net with similar problems and found some things like "Reserved Words" and "It must be your spacing". I did those and it still gives me the error. Am I missing something?
这是代码:
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();
}
推荐答案
Class
和 Section
均为保留字.像保留代码 [Password]
和 [Name]
一样,将它们括在方括号中.
Class
and Section
are both reserved words. Enclose them in square brackets as you have done for the reserved words [Password]
and [Name]
.
该页面包含Allen Browne的数据库问题检查器实用工具的链接.如果您具有包含Access的Office版本,则可以下载该实用程序并将其用于检查Access db文件中是否存在其他问题对象名称.
That page includes a link for Allen Browne's Database Issue Checker Utility. If you have a version of Office which includes Access, you can download that utility and use it to examine your Access db file for other problem object names.
这篇关于使用OleDb的INSERT INTO语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!