944,103 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 16301
  • ASP.NET RSS
Dec 6th, 2006
0

Search records in a database

Expand Post »
Hi,

I am creating a program that is connected to a database (Jet. OLEDB). I would like to know how can you search a record in the program.

Thanks
Similar Threads
jcf
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jcf is offline Offline
8 posts
since Dec 2006
Dec 7th, 2006
0

Re: Search records in a database

A search is bascially a query in the most basic sense. i.e. SELECT title FROM books WHERE author = "King, Stephen"

So the questions become;

What are you wanting to do for the search?

Do you want to search on one specifc criteria (i.e. Username or book title) ??

Do you want to do searches on concatnated strings? (i.e. A book tile by a specific author)

Please provide more details as to what you want to do specifically and I will be able to provide more details to assist you.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Dec 7th, 2006
0

Re: Search records in a database

If the users want to search for a certain keyword....they must type a keyword in a textbox.....then it will show the record that matches that keyword.

- so that if you have a lot of records in a database you can easily search for it.

Thanks for helping....I might have some more questions after these one.
jcf
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jcf is offline Offline
8 posts
since Dec 2006
Dec 9th, 2006
0

Re: Search records in a database

Following is a part of code to search a record and diaplay that record.

http://www.programmingknowledge.com/simpleDataGrid.aspx

=================================
Private Sub LoadPage() 
Dim strSQL As String = "SELECT * FROM JOB WHERE ID =" & 
Request.QueryString.Item("JobID") 
Dim cnn As New SqlClient.SqlConnection 
Dim cmd As SqlCommand 
Dim dr As SqlDataReader 
 
cnn.ConnectionString="Server=SERVERNAME;
_Database=DBNAME;uid=USER;pwd=PWD;" 
 
cnn.Open() 
cmd = New SqlCommand(strSQL, cnn) 
dr = cmd.ExecuteReader 
 
While dr.Read 
lblID.Text = dr("ID") 
txtJobName.Text = dr("JobName") 
txtJobDescription.Text = dr("JobDescription") 
End While 
End Sub

Last edited by Paladine; Dec 10th, 2006 at 8:41 pm. Reason: Added Tags
Reputation Points: 10
Solved Threads: 1
Newbie Poster
postmaster is offline Offline
19 posts
since May 2006
Dec 10th, 2006
0

Re: Search records in a database

Also try looking at some of the tutorials and posts about Login pages, etc on Dani Web as they contain good examples of searches from values entered into a textbox.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Nov 15th, 2007
0

Re: Search records in a database

Hi i have to do the project in ASP.net, could please send me code for search that are connected to sql Database.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Noonza is offline Offline
1 posts
since Nov 2007
Nov 15th, 2007
0

Re: Search records in a database

Noonza,

To do a search in a database, all you have to do is create a user control like Datalist, DataGrid, or Repeater and bind it to the datasource. If you want to search for a keyword, create a textbox that posts to the server. When a user enters in the information and submits, it will post to the server, and the your code will tell the SQL command what to search for. Then you need to bind that datasource to your user control. On the front-end of your page, you will need to design your search results and how they will display.

Create a page with a form running at the server. Create the textbox and submit button. On the submit button, create an OnClick command that posts to a sub on the server. Something like this would look like

OnClick="btnSearch_Click"

Then in your "Sub btnSearch_Click(...)" you will have the code to search the database using SQL parameters and the LIKE with % symbols. Then after it does the search, check to see if it "hasrows" with "repeatername.HasRows". If it is true, bind to the datasource.

Now create your Datalist, DataGrid, or Repeater on the page with your design/layout in the ItemTemplate tags. Then run your page and you have your results.

Done.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Nov 25th, 2008
0

Re: Search records in a database

please send me the code for that

please...please...please...please...please...please...
ASAP
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 25th, 2008
0

Re: Search records in a database

please send me the code as soon as possible
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Jul 24th, 2010
0
Re: Search records in a database
how to search paritcular thing in database and that has to view in gridview and how to delete/edit from frontend only. plz give the answer. its urgent. thank u
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shanwaz is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Repeater inside Repeater button
Next Thread in ASP.NET Forum Timeline: Fire repeters event on button click event Please Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC