Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Microsoft access 2007 as a database. I want to pass parameter for TOP keyword. i am using this code. i am passing txtQ1.Text as a parameter for TOP keyword but this give error.. could you please tell me the correct way to do that??

I am getting this error message.
ERROR MESSAGE :"The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."


<pre lang="c#">
OleDbConnection con7 = new OleDbConnection();
con7.ConnectionString = ConfigurationSettings.AppSettings["connecti"];
con7.Open();

OleDbCommand cmd7 = new OleDbCommand("delete ProductEntery FROM(select TOP @q * from ProductEntery)AS t1 where Produc_Name = @yo", con7);

cmd7.Parameters.Add(new OleDbParameter("@yo", txtname1.Text));
cmd7.Parameters.Add(new OleDbParameter("@q", txtQ1.Text));
cmd7.ExecuteNonQuery();
con7.Close();
</pre>
Posted
Updated 28-Feb-12 19:24pm
v2
Comments
André Kraak 29-Feb-12 1:20am    
Please specify the error message you are getting.

If you wish to change your question use the Improve Question button.
varuncodee 29-Feb-12 1:25am    
Thanks for the reply ..error message is "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."

1 solution

The TOP clause doesn't take parameters or variables. Build your string like this instread:

C#
"delete ProductEntery FROM(select TOP " + txtQ1.Text + " * from ".....
 
Share this answer
 
Comments
varuncodee 29-Feb-12 2:01am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900