VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Database Search Posted by Inspire_shin on 12 Apr 2009 at 8:02 PM
Hi,

Can someone show me the code to search the data in a database whereby the search keywords is provided by users ?

I have 3 search methods and when the user select the method and enter the keywords, the search is carried out within the search method meaning that if the search method is by name, the search is carried out within the name field. After the search button is press, all the record with the matching name will return and display in a datagrid.

Please help me. Thanks.
Report
Re: Database Search Posted by seancampbell on 14 Apr 2009 at 1:41 PM
This is a very straightforward process

Create a form where the user enter's criteria for the search
1) A textbox collects the search term
2) Radio buttons or checkboxes will be used to indicate what fields the user is searching
3) A button to tell the program to execute a search

When the user clicks the button the code logic is as follows:
1. Validate Entered Data (Check and make sure the search term is in the proper format for the database field you are searching on)
2. Build a SQL statement based on the user entry
(ex. Dim SQL as String = "SELECT * FROM TableName WHERE Field1 = '" & Textbox1.text & "'")
3. Open a Connection to the Database
4. Query for the data
5. Parse the data and populate a datagrid with the results
(step 5 might instead be binding the datagrid to the results instead of parsing the results)
6. Close the connection to the database

There are thousands of tutorials on connecting to databases with .net code... Here are some that will help you do build your search function:

http://www.homeandlearn.co.uk/NET/nets12p4.html (connect to an access dB)
http://www.startvbdotnet.com/ado/sqlserver.aspx (connect to a SQL Server Db)
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx (excelent tutorial on connection to SQL Server DB and binding that data to a Datagrid)

If you have code that won't work for you or need a specific command/function explained, I can help with that
Firesickle.com



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.