|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Select Where ClauseI am having a problem coding thw following stayement:
strSQL1 = "SELECT [service-order-number], taskid, [task-desc], [start-date], [start-time]" + " ,[task-status], [complete-date], [complete-time], [task-cost], [service-provider]" + " FROM [details] WHERE [service-order-number] = Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = " + tnum1; The above statement is where the problem is, if I only have one argument its fine. But when there are two arguments the code is wrong. Can someone please help me. Thanks -- Norm Bohana Norm,
You need to use the SQL keyword "AND" instead of "&" to connect the 2 conditions in the Where clause. Something like: strSQL1 = "SELECT [service-order-number], taskid, [task-desc], [start-date], [start-time]" + " ,[task-status], [complete-date], [complete-time], [task-cost], [service-provider]" + " FROM [details] WHERE [service-order-number] = " + Convert.ToInt32(txtServiceOrderNumber.Text) + " AND taskid = " + tnum1; Also, I would strongly recommend using parameters instead of merging textbox text and variables into the SQL statement. Kerry Moorman Show quote "nbohana" wrote: > I am having a problem coding thw following stayement: > strSQL1 = "SELECT [service-order-number], taskid, [task-desc], [start-date], > [start-time]" + > " ,[task-status], [complete-date], [complete-time], [task-cost], > [service-provider]" + > " FROM [details] WHERE [service-order-number] = > Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = " + tnum1; > The above statement is where the problem is, if I only have one argument its > fine. But when there are two arguments the code is wrong. Can someone > please help me. Thanks > -- > Norm Bohana strSQL1 = "SELECT [service-order-number], taskid, [task-desc], [start-date],
[start-time]" + " ,[task-status], [complete-date], [complete-time], [task-cost], [service-provider]" + " FROM [details] WHERE [service-order-number] = Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = " + tnum1; Your placement of quotes looks funny to me too How come you have put Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = inside quotes? Convert.ToInt32(txtServiceOrderNumber.Text) Has to be outside of quotes. And of course as Kerry pointed out, you have to use AND instead of & (ampersand) Should I point you to some good resourced on SQL? Try w3cschools. They have an excellent little tutorial Regards Cyril Gupta Thank you both!!!.
-- Show quoteNorm Bohana "Cyril Gupta" wrote: > strSQL1 = "SELECT [service-order-number], taskid, [task-desc], [start-date], > [start-time]" + > " ,[task-status], [complete-date], [complete-time], [task-cost], > [service-provider]" + > " FROM [details] WHERE [service-order-number] = > Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = " + tnum1; > > Your placement of quotes looks funny to me too > > How come you have put Convert.ToInt32(txtServiceOrderNumber.Text) & taskid = > inside quotes? > > Convert.ToInt32(txtServiceOrderNumber.Text) > > Has to be outside of quotes. And of course as Kerry pointed out, you have to > use AND instead of & (ampersand) > > Should I point you to some good resourced on SQL? > > Try w3cschools. They have an excellent little tutorial > > Regards > Cyril Gupta > > > |
|||||||||||||||||||||||