Click here to Skip to main content
15,918,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Access 2007 database with C# windows application I create a query to find the party names from the table payment_voucher using like and i also want to find the vouchers by entering voucher amount

My query is like following
select voucher_date as VCDate,voucher_code as VoucherNo,receiver_name as PartyName,expense_head_name as Purpose,voucher_amount as Amount from payment_voucher where voucher_code='" + txt_vc_number.Text + "' or receiver_name Like '" + txt_party_name.Text + "' or voucher_amount='" + amt + "'


But it does not shows the record to me if i entered R in party name text box and it also shows error when i entered amount in a amount text box

it shows the error that
Data type mismatch in criteria expression.


Please help me remove this error
Posted
Updated 4-Oct-14 21:05pm
v2
Comments
Richard MacCutchan 5-Oct-14 3:28am    
You can fix it yourself by creating proper parameterized queries, rather than using the lazy way. Which is also wide open to SQL injection attacks. As you create each parameter you can validate the inputs and convert them to the proper types where necessary.
Omkar Hendre 5-Oct-14 3:33am    
sorry sir i am new to development filed so i don't know how to validate the files and convert them but i will search for it and try to implement this thanks for big suggestions
Omkar Hendre 5-Oct-14 3:43am    
sir i try to execute the above query in every manner but does not give any records can you please help me to solve my problem

1 solution

Try removing the single quote around the amt variable:
C#
select voucher_date as VCDate,voucher_code as VoucherNo,receiver_name as PartyName,expense_head_name as Purpose,voucher_amount as Amount from payment_voucher where voucher_code='" + txt_vc_number.Text + "' or receiver_name Like '" + txt_party_name.Text + "' or voucher_amount=" + amt + "
 
Share this answer
 
Comments
Omkar Hendre 5-Oct-14 3:59am    
Yes sir i remove it but like is not working
Mehdi Gholam 5-Oct-14 4:03am    
If you want to search inside a value with like you should use % before and after the variable -> like '%" + txt_party_name.Text + "%'
Omkar Hendre 5-Oct-14 4:10am    
wait i check it and let you know and thanks for helping me
Omkar Hendre 5-Oct-14 4:11am    
Great it works fine but if i want to check for starting letter then what i should do
Omkar Hendre 5-Oct-14 4:12am    
i got it

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