Parameters annd SQLDataAdapter

  • Thread starter Thread starter Denis Blondeau
  • Start date Start date
D

Denis Blondeau

Is it possible to use a wildcard as a parameter? For example, sometime I
want to use a paramater to get only a subset of rows in a table but sometime
I want to get all the rows.

I tried deleting the parameter itself (e.g. @CallID) but I will get an SQL
adapter as the parameter, even if deleted, is still in the Commandtext of
the SQLAdapter.

The only way I can get this to work is to also modify the commandtext (i.e.
removing any reference to that parameter in the SELECT command).

-> Denis
 
The way that I've done this in the past is to use null as the default
value for the parameter and not pass it if needed.

creates objects (Command, Connection, etc.)

if (Parameter required)
add it
end if

call ExecuteXXX

And then the SP would be (or whatever you need to do - just check for IS
NULL):

CREATE PROCEDURE dbo.stpTest
@id int = null
AS

IF (@id IS NULL) BEGIN

END ELSE BEGIN

END
 
Hi Denis,

Nope, it is not possible directly. There are workarounds though - you could
modify sql select command in the way that if gets null value of a parameter
it ignores it.
Or, you could build on the fly your sql select command and add those
parameters you need.
 
Back
Top