Hi! When my login form is loaded, I wish to retrieve the list of usernames from the database login to a combo box on the login form. unfortunately I am stuck with this error messsage " syntax error in FROM clause". Below is my codes.. help me out please
Thank you.

String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:/Documents and Settings/Farheen/My Documents/login.mdb";

            //create and open the connection
            OleDbConnection conn = new OleDbConnection(connStr);

            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT * FROM user";

            //set up the adapter
            OleDbDataAdapter da = new OleDbDataAdapter("Select UserName from user",conn);
            da.SelectCommand = cmd;
            //create the dataset
           DataSet ds = new DataSet();

            cbo_Username.DisplayMember = "UserName";
            cbo_Username.DataSource = ds.Tables[0];


The problem is that 'user' is a sql keyword. Whilst it is syntactically possible to use keywords, it is best to avoid them. It is similar to trying to declare an variable like decimal decimal = 2; . In C# this throws an error, in SQL it will allow it.
To keep your column name as it is, use delimited identifiers ('[]') to ensure that the keyword is treated the way you intend it:

Select UserName from [user]


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.