Select Where Clause

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

sqlDataAdapters/ 5
Binding Data 6
data binding 2
System.Data.NoNullAllowedException 3
Macro Problems in excel 2007 1
Convert string to int 5
Merging a series of queries into one 2
Guidance on remoting 6

Back
Top