P
Philip Tepedino
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
(e-mail address removed)
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
(e-mail address removed)