查询表达式中的语法错误(缺少运算符) [英] Syntax Error (Missing Operator) In Query Expression "

查看:588
本文介绍了查询表达式中的语法错误(缺少运算符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试编写一个SQL查询,其中我使用内部联接从一个表中获取数据并在另一个表中显示匹配的内容,但是我在查询表达式"中收到错误语法错误(缺少运算符)".确定我在哪里出错了,但是我已经插入了我正在使用的代码,对我来说它看起来是正确的.

Trying to write an SQL query where I'm using an inner join for getting data from one table and display matched contents in another table, however I receive the error 'Syntax error (missing operator) in query expression "'. Not sure where I'm going wrong with this, however I've inserted the code I'm using, and it looks correct to me.

顺便说一句,该代码已作为VB程序的一部分编写,因此是在SQL代码旁边的额外代码.

By the way, the code has been written as part of a VB program, hence the extra code beside the SQL code.

Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [classes] INNER JOIN [students] ON classes.StudentForename = students.Forename AND ON classes.StudentSurname = students.Surname AND ON classes.TeacherName ='" & personloggedon.Text & "' AND ON classes.Day ='" & System.DateTime.Now.DayOfWeek.ToString & "' AND ON classes.Period ='" & attendance_reg_periodComboBox.Text & "'", con)

我也尝试再次使用下面的代码,但不起作用.

I've also attempted to use the following code also, again, not working.

Dim cmd as OleDbCommand = New OleDbCommand("SELECT [Forename], [Surname] FROM [classes] INNER JOIN [students] ON classes.StudentForename = students.Forename AND ON classes.StudentSurname = students.Surname AND ON classes.TeacherName ='" & personloggedon.Text & "' AND ON classes.Day ='" & System.DateTime.Now.DayOfWeek.ToString & "' AND ON classes.Period ='" & attendance_reg_periodComboBox.Text & "'", con)

我所有的SQL查询需要做的就是从类"数据库中获取姓氏和姓氏,只要它们符合给定的条件,然后取自所述数据库给出的姓氏和姓氏并匹配学生"数据库.然后从那里显示在我程序的datagridview中.

All my SQL queries need to do is get the forenames and surnames off of the "classes" database as long as they match up to the criteria given, then take the forenames and surnames given from said database and match up to the "students" database. From there, it is then displayed in a datagridview on my program.

我对SQL编码还比较陌生,所以如果错误特别明显,我先向您道歉!但是,非常感谢所有帮助.

I'm relatively new to SQL coding, so if the error is particularly obvious, I apologise in advance! However, all help is greatly appreciated.

推荐答案

您的ON太多.将所有AND ON替换为AND.

You have too many ONs. Replace all AND ON with just AND.

Dim cmd as OleDbCommand = New 
OleDbCommand("SELECT [Forename], [Surname] FROM 
[classes] INNER JOIN [students] ON 
classes.StudentForename = students.Forename AND 
classes.StudentSurname = students.Surname WHERE 
classes.TeacherName ='" & personloggedon.Text & "' 
AND  classes.Day ='" & 
System.DateTime.Now.DayOfWeek.ToString & "' AND 
classes.Period ='" & 
attendance_reg_periodComboBox.Text & "'", con)

您确实要考虑使用参数化查询,以避免注入攻击.

You really want to look at using parameterised queries though to avoid injection attacks.

这篇关于查询表达式中的语法错误(缺少运算符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆