i am using visual stdio 2开发者_JAVA技巧008 and sql server 2005
dim selectquery = "SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= " + cboPDate.SelectedValue.ToString()
when this selectquery executed it gives me error
"ERROR near syntax 12"
my cboPDate is a combobox binded with my database which return's data and time in "2/18/2011 12:00:00 AM"
please help me out
You need to add quotes around your date.
Try
dim selectquery = "SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= '" + cboPDate.SelectedValue.ToString() +"'"
Better yet, use SQL parameters.
I suspect it is treating it as a delimiter.It would be better to change it to
WHERE Purchase_master.Date=@Your_date
And then add the date as a parameter, this would prevent SQL injection attacks and also promote plan caching
Try this:
dim selectquery = string.Format("SELECT Purchase_master.Customer_name, Purchase_details.Item_code, Item_Master.Name,
Purchase_details.Quantity, Purchase_details.Cost, Purchase_master.Date
FROM Item_Master INNER JOIN (Purchase_master INNER JOIN Purchase_details ON
Purchase_master.Bill_id = Purchase_details.Bill_id) ON Item_Master.Item_code = Purchase_details.Item_code
WHERE Purchase_master.Date= '{0}'", cboPDate.SelectedValue.ToString());
you have to add quots to the value. :)
精彩评论