1
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

5
  • 1
    what is Registrations list Commented Sep 2, 2015 at 17:53
  • Have you tried executing the SQL command as-is to see if you can reproduce the error? That may lead you to what is causing the problem. Commented Sep 2, 2015 at 17:53
  • Yes but nothing seems to work Commented Sep 2, 2015 at 17:55
  • 1
    Can you post the schema for the table? The problem seems to be with how you are referencing the column in your SELECT. Commented Sep 2, 2015 at 17:56
  • can you add the stack trace of the error? Commented Sep 2, 2015 at 20:25

3 Answers 3

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]

Sign up to request clarification or add additional context in comments.

2 Comments

@Johnugo:- Can you tell us the exact error which you are getting when you execute the above query?
you need to do it in the select query itself.
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.

Comments

0

I suppose there is an error in the 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.

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.