Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 在Visual Basic 2010到MS ACCESS 2007上执行INSERT INTO命令时出现语法错误_Database_Vb.net_Insert_Ms Access 2007 - Fatal编程技术网

Database 在Visual Basic 2010到MS ACCESS 2007上执行INSERT INTO命令时出现语法错误

Database 在Visual Basic 2010到MS ACCESS 2007上执行INSERT INTO命令时出现语法错误,database,vb.net,insert,ms-access-2007,Database,Vb.net,Insert,Ms Access 2007,在以下代码上运行调试时,我不断遇到语法错误: 请告诉我有什么问题吗?您有一些字段名包含空格。要使用这些字段名,需要将它们括在方括号中 cmd.CommandText = "INSERT INTO First_Year " & _ "(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX, " & _ "SY,CIVIL_STATUS,Religion,Birthdate

在以下代码上运行调试时,我不断遇到语法错误:


请告诉我有什么问题吗?

您有一些字段名包含空格。要使用这些字段名,需要将它们括在方括号中

 cmd.CommandText = "INSERT INTO First_Year " & _
            "(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX, " & _
            "SY,CIVIL_STATUS,Religion,Birthdate,TEL_NO,Father,Occupation_F,Mother, " & 
            "Occupation_m,[School Last Attended],[Address School],Middle_Name) " & 
            "...... "
尽管如此,请记住,像您这样的字符串连接会导致Sql注入,并在解析包含引号(O'Brien)、十进制数或日期的字符串时出现问题

搜寻

查询的参数化方法是

cmd.CommandText = "INSERT INTO First_Year " & _
        "(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX, " & _
        "SY,CIVIL_STATUS,Religion,Birthdate,TEL_NO,Father,Occupation_F,Mother, " & 
        "Occupation_m,[School Last Attended],[Address School],Middle_Name) " & 
        "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
cmd.Parameters.AddWithValue("@p1", Me.sn.Text)
cmd.Parameters.AddWithValue("@p2", Me.fn.Text)
... and so on for the remainder 16 parameters placeholders 
... respecting their position and converting to the appropriate datatype

您需要删除此处的空格(在查询中):

或者这样写:

..........[School Last Attended],[Address School]..........

请你也附上你收到的错误信息的截图或逐字记录。
......School Last Attended,Address School.......
..........[School Last Attended],[Address School]..........