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
我试图让数据库值显示在文本框中但不断得到错误,我已经尝试了大部分可能的事情
3 个解决方案
#1
1
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]
#2
0
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会将其视为两个列名,因为逗号也不会出现,因此它会给出语法错误。
#3
0
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
. If you want to label the column place the keyword as
between the column name and uts label.
在SELECT和FROM之间,应该有一个以逗号分隔的列列表,这些列可以绑定到表Records。如果要标记列,请将关键字放在列名和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.
如果你在列名中放置了一个空格(从未见过,从未见过,甚至根本不知道它是否可能),请尝试在单引号之间包含列名。或者(更好)重命名列。
#1
1
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]
#2
0
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会将其视为两个列名,因为逗号也不会出现,因此它会给出语法错误。
#3
0
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
. If you want to label the column place the keyword as
between the column name and uts label.
在SELECT和FROM之间,应该有一个以逗号分隔的列列表,这些列可以绑定到表Records。如果要标记列,请将关键字放在列名和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.
如果你在列名中放置了一个空格(从未见过,从未见过,甚至根本不知道它是否可能),请尝试在单引号之间包含列名。或者(更好)重命名列。