| | |
Search records in a database
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
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.
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.
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.
- 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.
•
•
Join Date: May 2006
Posts: 19
Reputation:
Solved Threads: 1
Following is a part of code to search a record and diaplay that record.
http://www.programmingknowledge.com/simpleDataGrid.aspx
=================================
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
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.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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.
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.
![]() |
Similar Threads
- Search code in a database (Visual Basic 4 / 5 / 6)
- How to Search record from the Sql Server Database (ASP.NET)
- ASP .NET Display Random records from the database (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: gridview visible when keypress
- Next Thread: Online Payment Options
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# cac checkbox class commonfunctions compatible content contenttype countryselector courier dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iframe iis javascript listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers






