简体   繁体   English

sql查询表达式中的语法错误(缺少运算符)

[英]syntax error (missing operator) in sql query expression

try
        {

            string Query = "SELECT Registrations list FROM [Records] WHERE textBox = '" + comboBox.SelectedValue + "'";
            OleDbConnection me = new OleDbConnection(connection);
            OleDbCommand constr = new OleDbCommand(Query, me);
            OleDbDataReader reader;
            connection.Open();
            reader = constr.ExecuteReader();

            if (reader.Read())
            {
                OleDbParameter parameter = constr.Parameters.Add(new OleDbParameter("Registrations list", OleDbType.Integer));
                textBox.Text = reader["Registrations list"].ToString();
            }
            me.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

Im trying to get database values to display in textbox but keep getting the error, i've tried mostly everything possible 我正在尝试让数据库值显示在文本框中,但不断出现错误,我已经尝试了所有可能的方法

wrap the column name with square brackets 用方括号包裹列名

SELECT [Registrations list] FROM [Records] WHERE textBox

Otherwise sql server looks for a column called Registrations and then tries to alias it as [List] 否则,sql server将查找名为Registrations的列,然后尝试将其别名为[List]

Enclose the column name in square brackets. 将列名称括在方括号中。

SELECT [Registrations list] 

If the column names contais space then you need to enclose the column name in square brackets else SQL Server will consider it as two column names and since comma will also be not present hence it will give you syntax error. 如果列名称包含空格,则需要将列名称括在方括号中,否则SQL Server会将其视为两个列名称,并且由于逗号也不存在,因此会给您语法错误。

I suppose there is an error in the SQL 我想SQL中有错误

string Query = "SELECT Registrations list FROM [Records] WHERE textBox = '" + comboBox.SelectedValue + "'";

Between SELECT and FROM there should be a comma separated list of columns belinging to the table Records . SELECTFROM之间,应该有一个逗号分隔的列列表,这些列依附于表Records If you want to label the column place the keyword as between the column name and uts label. 如果你想标记栏放置关键字as列名和UTS标签之间。

If you placed a white space in the column name (never saw, never did, don't even know if it's possible at all), try including the column name between single quotes. 如果您在列名称中放置了一个空格(从没看过,从未做过,甚至根本不知道是否有可能),请尝试在单引号之间包含列名。 Or (much better) rename the column. 或者(更好)重命名列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查询表达式“”中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression “” 查询表达式中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression 语句中查询表达式中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression in statement 查询表达式'[Code] IN('中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression '[Code] IN(' 查询表达式中缺少语法错误运算符 - syntax error missing operator in query expression C# 中的 SQL 查询(System.Data.OleDb.OleDbException:'查询表达式中的语法错误(缺少运算符)) - SQL query in C# (System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression) 获取异常错误说:查询表达式中的语法错误(缺少运算符) - Getting Exception error saying: Syntax error (missing operator) in query expression 查询表达式中的C#语法错误(缺少运算符) - C# Syntax error (missing operator) in query expression OleDbException未处理:查询表达式中的语法错误(缺少运算符) - OleDbException was unhandled: Syntax Error (missing operator) In Query Expression 日期和时间查询表达式中缺少运算符的语法错误 - syntax error missing operator in date and time query expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM