Parameters for DataAdapter

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

Guest

I'm creating a simple search for Members, with possible 4 search parameters:
Name, SSN, DOB, SEX, but (just beginning ASP.NET/VB.NET) I'm fearing that I
will need to create a dataadapter for every possible combination of fields
entered to eliminate a blank parameter.

Does a parameterized DataAdapter automatically take care of this so I can
use the following SQL without having to worry about blank textboxes?:

SELECT * From Membership WHERE
Name = @txtName AND
SSN like @txtSSN AND
DOB like @txtDOB AND
SEX like @txtDOB

Presently, in my Access application, I've had to write a separate strSQL for
each possible combination as to avoid creating a SQL statement with a blank
parameter.

Thanks so much for anything to help with this...
 
Jonefer,

AFAIK it does not, I wish it was there.

In addition, because of the fact that it is Access, do you have in my
opinion as well not much alternatives. Be aware that in OleDB the parameter
name does nothing, it is the sequence that they are declared which counts in
OleDB.

(A ? does as much as a name)

http://www.vb-tips.com/default.aspx?ID=550279ec-6767-44ff-aaa3-eb8b44af0137

Although you are very much welcome here, a better newsgroups for this kind
of questions is.

microsoft.public.dotnet.framework.adonet

I hope this helps,

Cor
 
Why not build the string when you require it? I'm assuming that you're
getting the values from a text box or something similar. Not quite proper
code but it gives you the idea

Function BuildQuery(txtName, txtSin, txtDOB, txtSex) as string
DIM QryStr as String = "SELECT * FROM MEMBERSHIP WHERE "
DIM QrySIN, QryDOB, QrySex as string

if txtName <> "" Then QryStr = QryStr & "NAME = @txtName"
if txtSIN <> "" Then
if QryName <> "" then QrySIN = " AND "
QrySIN = QrySIN & "SSN = @txtSSN"
enf if

'similar conditions


Return QryStr
End

May not be pretty, but I've used it before
 
Back
Top