|
-
Aug 21st, 2003, 09:42 AM
#1
Thread Starter
Fanatic Member
Search Form - how to implement?
I need to develop a search screen for an object. I know I need to build my SQL statement in code rather than a Stored Procedure (which sucks), but is there any examples or methodology on how to implement the build of the SQL statement. I want to allow searching by any number of fields and also allow "starts with", "ends with", "contains" type of searching for each field.
Thanks.
-
Aug 21st, 2003, 04:07 PM
#2
I wonder how many charact
Phew, what a fun exercise that will be!
I guess what you're asking is:
if I had x number of tables each with their respective fields, and wanted to Search all of them for a given value?
Is that accurate?
-
Aug 21st, 2003, 04:11 PM
#3
Thread Starter
Fanatic Member
Not exactly. I will have to search more than 1 table as my object contains values from more than one table. So I want to allow the user to search by any of the properties in the object, and return a collection of that object type.
-
Aug 21st, 2003, 04:18 PM
#4
-
Aug 21st, 2003, 04:43 PM
#5
I wonder how many charact
This is going to be a work in progress for me... so if anyone else has done this code before... please feel free to jump in:
Step 1) We're going to need represent a map of the data.. iterating from 1 for a parent level to n representing the last child of that parent.
So if we have a field called City... we need to identify that field with a table, and the owner table with its parent table if any.
Step 2) To create the map, we need to get all the tables first using GetOleDbSchemaTable method of OleDbConnection for OLE DB data sources or by using Select sysobjects for SQL Server.
Then we need to use DataReader's GetSchemaTable.. so we can examine the table's setup.
Step 3) Somehow we need to map the data in the database to our program's objects. Let's take a scenario where the user wants to return all orders from John Doe.
In the Database
We might have a table called CustomerOrders that simply lists a customerID and an OrderID.
The order would have an order number, the customer would have a name. They are linked to foreign fields... we should be able to devise a way to find the datarows in the two tables and return both rows.
In our program
The hard part of course is translating that data into a useable object.
I can envision a XML mapping that could be changed as new fields are added to tables over the lifecycle of the program.
So we would need a person to modify that XML file so we translate that an ORDER search will scan the CustomerORders table, and return information from the Customer's table and the Order's table.
<Search>
--<Name>Customer Order Search</Name>
-----<ProgramObject>Orders</ProgramObject>
------<ParentTable>
------<Name>CustomerOrders</Name>
------<Children>
----------<ChildTable>
------------------<Name>Customers</Name>
------------------<SQLStatement>Select * From Customers where ID = [parameter]</SqlStatement>
-----------</ChildTable>
------------<ChildTable>
-------------------<Name>Orders</Name>
-------------------<SQLStatement>Selet * From ORders where ID = [parameter]</SQLStatement>
--------------</ChildTable>
--------</Children>
---------</ParentTable>
--</Search>
Phew.. I'm tired already.
(more to come in about a day)
Last edited by nemaroller; Aug 21st, 2003 at 05:03 PM.
-
Aug 21st, 2003, 05:43 PM
#6
I wonder how many charact
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|