Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reserved Wording in SELECT statement?

Status
Not open for further replies.

knight1001

Technical User
Nov 29, 2004
14
0
0
GB
Exception Details: System.Data.OleDb.OleDbException: The
I keep recieving this error, can't possibly think about why its saying it as there are no reserved words.

SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

Source Error:


Line 49: connectionxy.Open();
Line 50:
Line 51: readerxy = commandxy.ExecuteReader();
Line 52: if (readerxy.Read())
Line 53: {


Here is the code including the SELECT statement.

Code:
private void ButtonFetch_Click(object sender, EventArgs e)
{
  commandxy = new OleDbCommand("SELECT Cars.[Team Name], Cars.[Factory Day], Cars.[Engine Make], Cars.[Main Sponsor], FROM Cars WHERE Cars.[Car No] = @No;");
  commandxy.Parameters.Add(new OleDbParameter("@No", OleDbType.Integer));
  commandxy.Parameters.Add(new OleDbParameter("@No", OleDbType.Integer));
  commandxy.Parameters["@No"].Value = ListCarNo.SelectedValue;
  commandxy.Connection = connectionxy;

  connectionxy.Open();
  
  readerxy = commandxy.ExecuteReader();	
  if (readerxy.Read())
 
First off, looks like you are adding the "@No" parameter twice.

Also, I see that the parameter is of interger type, but you give it a value from ListCarNo.SelectedValue, which is a string.

Consider an alternate syntax:
Code:
commandxy.Parameters.Add(new OleDbParameter("@No", Int32.Parse(ListCarNo.SelectedValue)));

that's adding a new parameter and setting it's value in one line.


[pipe]
Share your knowledge! -
 
I also see in your sql statement you have a comma in front of Cars.[Main Sponsor]
 
linuxjr has identified the error. Basically you have:
Code:
...Cars.[Main Sponsor], FROM...
which means when the DB engine reads the SQL, it sees FROM as another column that you want to select, and FROM is a reserved word.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top