Searching Database - Design Best Practices

T

thomson

Hi All,
i have a sit which deals with cars, and i have a table
associated with this, i do have a problem in designing the
application, i have lot of places in the web page where it hits the
the same table but the criteria (parameters) will be different,

Can some body help me out in designing a class which suits the above
purpose , or sugggest me Best Practices for the same

Thanks in advance

thomson
 
G

Guest

Mmmm....

It can more complicated but... maybe this simple approach can feed your
needs: Create an stored procedure with all the search params that you need,
set the default value of each param to NULL.

Now in the select where you filter use this approach (pseudo SQL here):

DECLARE My Store Proc
MyParam1 Int = NULL,
MyPAram2 varchar(80) = NULL,
(...)

SELECT ...
FROM ...
WHERE
(MyParam1 IS NULL OR tablefield1 = MyParam1)
AND
(MyParam2 IS NULL OR tablefield1 = MyParam2)

By using this approach you control if the param has been informed using
the IS NULL and the OR switch, and you avoid having chunking T-SQL IF
statements.

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 
S

sloan

What I do is create a strong dataset.

If you read the article, you'll notice I had a

ParameterDS

which is a strong dataset.

Basically, I code one of these up.
And as the user checks/selects items from a form, I add entries to an
instance of this dataset.

So I might show:

CheckBox list of Customers
2 Text Boxes... for a "Orders After This Date" and "Orders Before this
Date".
DropDownList of Countries.

Then I can loop/find the values they picked.

Something like this (This is PSEUDO code, not working code).

ParameterDS ds = new ParameterDS();

for each ( Selected Check Box in chkAllCustomers )
{
ds.Customer.AddNewCustomerRow ( selected check box . Value ) ;

}
if(ddlCountries.SelectedItem Is Picked)
{
ds.Countries.AddNewCountryRow( ddlCountries.SelectedValue ) ;
}




And I then ship this dataset .GetXml() to the stored procedure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top