What is the database and table name? What fields in your table do you want to search, and what do you want to search them for? Can you provide some examples?
Search by database is made by LIKE clause. Use it as
SELECT * FROM UserProfile WHERE Name LIKE 's%'
This way database will be searched for every name that is starting from S
You said you have StarterSite, There UserProfile table is present. And NAME IS NOT PRESENT. I have used it for my own answer!
So you can see from the query, that the table UserProfile will be searched, if you have any other table use its name. WHERE "NAME", I used NAME if you have any other column name use that. And LIKE is used to tell the server to search for any result with the name starting from S
You can use it as
SELECT * FROM UserProfile WHERE Name LIKE '%s'
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
Thanks for your response. The name of databse is firstphase and the table name is customers. I want to have a textbox on the site page that will search the customer table by name and display the results in a gridview table.
// The name of databse is firstphase and the table name is customers
var search = "SELECT * FROM Customers WHERE Name LIKE 's%'";
var db = Database.Open("firstphase");
var result = db.Query(search);
This will search your firstphase database's table customers, give result where name will be starting from S
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
MicMoore76
0 Points
3 Posts
Search Box help!!!
Jan 31, 2013 10:25 AM|LINK
I have a starter site with the neccesary databse table setup. I need to a text box that can search my table in the database. Please help
oned_gk
All-Star
31515 Points
6433 Posts
Re: Search Box help!!!
Jan 31, 2013 10:59 AM|LINK
add autopostback textbox and gridview. configure datasource to use sqldatasource and configure it trought wizard
Mikesdotnett...
All-Star
154887 Points
19862 Posts
Moderator
MVP
Re: Search Box help!!!
Jan 31, 2013 12:50 PM|LINK
What is the database and table name? What fields in your table do you want to search, and what do you want to search them for? Can you provide some examples?
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Search Box help!!!
Feb 01, 2013 09:12 AM|LINK
Search by database is made by LIKE clause. Use it as
This way database will be searched for every name that is starting from S
You said you have StarterSite, There UserProfile table is present. And NAME IS NOT PRESENT. I have used it for my own answer!
So you can see from the query, that the table UserProfile will be searched, if you have any other table use its name. WHERE "NAME", I used NAME if you have any other column name use that. And LIKE is used to tell the server to search for any result with the name starting from S
You can use it as
~~! FIREWALL !~~
MicMoore76
0 Points
3 Posts
Re: Search Box help!!!
Feb 05, 2013 11:49 PM|LINK
Thanks for your response. The name of databse is firstphase and the table name is customers. I want to have a textbox on the site page that will search the customer table by name and display the results in a gridview table.
Mikesdotnett...
All-Star
154887 Points
19862 Posts
Moderator
MVP
Re: Search Box help!!!
Feb 06, 2013 05:09 AM|LINK
The basics behind searching and displaying the results in a WebGrid are described in this article: http://www.mikesdotnetting.com/Article/180/Displaying-Search-Results-In-A-WebGrid
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Search Box help!!!
Feb 06, 2013 08:52 AM|LINK
The query for this would be
// The name of databse is firstphase and the table name is customers var search = "SELECT * FROM Customers WHERE Name LIKE 's%'"; var db = Database.Open("firstphase"); var result = db.Query(search);This will search your firstphase database's table customers, give result where name will be starting from S
~~! FIREWALL !~~
oned_gk
All-Star
31515 Points
6433 Posts
Re: Search Box help!!!
Feb 06, 2013 10:48 AM|LINK
Just define the connection string for below code, no need code behind
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM customers WHERE name like '%' + @search + '%'"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="search" PropertyName="Text" /> </SelectParameters> </asp:SqlDataSource>Mikesdotnett...
All-Star
154887 Points
19862 Posts
Moderator
MVP
Re: Search Box help!!!
Feb 06, 2013 06:50 PM|LINK
This is the Web Pages forum, not the Web Forms one. Server controls won't work in Razor pages.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
oned_gk
All-Star
31515 Points
6433 Posts
Re: Search Box help!!!
Feb 07, 2013 12:33 AM|LINK
Appologize me