[英]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
. 在
SELECT
和FROM
之间,应该有一个逗号分隔的列列表,这些列依附于表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.