Hello,

I'm having a hard time getting used to all this new ADO stuff.
I have many applications written in VB6 and am starting to slowly re-do them
in .NET
What I've read suggests that I should use parameters to pass information to
a query string instead of creating the string piece by piece. Thats fine
with me, I like that. My problem is: Whats the best way to deal with
parameters that you don't have info for?

Here is an example:
I set a SqlCommand to something like "SELECT * FROM tblEmps WHERE (ID = @ID)
AND (Unit LIKE @Unit)

So lets say my form has two text boxes, txtID and txtUnit
Unit is a string, and ID is an integer

Now the user fills in the txtUnit textbox with "John" or something, and
leaves the ID (txtID) blank.

If I add both parameters to the adapter, then nothing shows up because it is
adding "" (or a 0 when converted to integer i guess) to the @ID parameter.
IF I don't add a value for @ID, then it gives me an exception error.

My question is:
Is there a way I can NOT add a parameter that was defined in my SqlCommand?
and if not, how do I deal with textboxes that the user might not fill out
(its easy for strings.. just use LIKE and add "%" as the parameter)

Am I doing this the wrong way? How should I deal with forms that have many
inputs, some of which might be left blank?

Thanks for any help,

Philip Tepedino
Siemens Westinghouse Generation Services
Software/Database Development
ftepedino@swgs.net

Re: SqlDataApapter Parameters Question by William

William
Wed Sep 17 23:06:34 CDT 2003

For this case, one approach would be to pass a "%" as the LIKE argument
parameter--it's perfectly alright--but the LIKE expression is intended for
strings--not integers. Use BETWEEN or other numeric expressions for numbers.
If you create a stored procedure to run this query you can specify default
parameter values as well.

hth

--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Philip Tepedino" <ftepedino@swgs.net> wrote in message
news:%23PwE6GVfDHA.908@tk2msftngp13.phx.gbl...
> Hello,
>
> I'm having a hard time getting used to all this new ADO stuff.
> I have many applications written in VB6 and am starting to slowly re-do
them
> in .NET
> What I've read suggests that I should use parameters to pass information
to
> a query string instead of creating the string piece by piece. Thats fine
> with me, I like that. My problem is: Whats the best way to deal with
> parameters that you don't have info for?
>
> Here is an example:
> I set a SqlCommand to something like "SELECT * FROM tblEmps WHERE (ID =
@ID)
> AND (Unit LIKE @Unit)
>
> So lets say my form has two text boxes, txtID and txtUnit
> Unit is a string, and ID is an integer
>
> Now the user fills in the txtUnit textbox with "John" or something, and
> leaves the ID (txtID) blank.
>
> If I add both parameters to the adapter, then nothing shows up because it
is
> adding "" (or a 0 when converted to integer i guess) to the @ID parameter.
> IF I don't add a value for @ID, then it gives me an exception error.
>
> My question is:
> Is there a way I can NOT add a parameter that was defined in my
SqlCommand?
> and if not, how do I deal with textboxes that the user might not fill out
> (its easy for strings.. just use LIKE and add "%" as the parameter)
>
> Am I doing this the wrong way? How should I deal with forms that have many
> inputs, some of which might be left blank?
>
> Thanks for any help,
>
> Philip Tepedino
> Siemens Westinghouse Generation Services
> Software/Database Development
> ftepedino@swgs.net
>
>
>