Home All Groups Group Topic Archive Search About
Author
5 Jan 2006 8:23 PM
nbohana
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

Author
5 Jan 2006 8:45 PM
Kerry Moorman
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
Author
6 Jan 2006 7:58 AM
Cyril Gupta
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
Author
6 Jan 2006 10:31 PM
nbohana
Thank you both!!!.
--
Norm Bohana


Show quote
"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
>
>
>

AddThis Social Bookmark Button