My SQL query is
cmd = new OleDbCommand("select vchr_No as voucher No, vchr_Date as Date,
vchr_Acnthd as Debit, vchr_Prtynm as Paid to
from cshvchrs
where vchr_No like '%" + vchno + "%' ", con);
When I try to retrieve the data I am getting an exception:
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
Please anybody help me
You have invalid SQL - the aliases that contain spaces need to be escaped, as do aliases that are keywords.
cmd = new OleDbCommand("select vchr_No as [voucher No] ,vchr_Date as [Date] ,vchr_Acnthd as Debit ,vchr_Prtynm as Paid to from cshvchrs where vchr_No like '%" + vchno + "%' ", con);
On vchr_Date as Date part,
Date is a reserved keyword on Transact-SQL.
Reserved keywords are part of the grammar of the Transact-SQL language that is used by SQL Server to parse and understand Transact-SQL statements and batches.
You can use it with square brackets [] like;
vchr_Date as [Date]
Use your full query as;
cmd = new OleDbCommand("select vchr_No as [voucher No] ,vchr_Date as [Date] ,vchr_Acnthd as Debit ,vchr_Prtynm as Paid to from cshvchrs where vchr_No like '%" + vchno + "%' ", con);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With