Vb.net – search database SQL like query

asp.netvb.net

I have created a bookshop website with database, I need a search engine that will search the database records and present the user with results according to the keyword.

I have created the page with the text search box and search button

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Search
</h2>
<p>
    Search box.
</p>

<table border="0" cellpadding=5 bgcolor=><tr> <td align="center"> 
<asp:TextBox ID="search_box" runat="server" Width="200px"></asp:TextBox>&nbsp;&nbsp; 
<asp:Button ID="Button1" runat="server" Text="Search" Height="19px" 
    Width="75px" />
</td> 
</tr>
</table> 
    <div style="text-align: center">
        <br />
        <span id="Span1" runat="Server" style="Color:Red"></span>
    </div>

and this is the code behind so far

Partial Class Search
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    SELECT * FROM BOOKS
        WHERE Title like '%"search_box.text"%'


End Sub

End Class

Best Solution

VB.Net doesn't understand SQL... it's not as easy as just giving it a SQL Query; you need to use some type of data access layer, probably ADO.Net, and specify which SQL Server your application should connect to, how it should connect to it, etc.

I'd recommend running through a simple tutorial on connecting to SQL through VB.Net.

http://www.fryan0911.com/2009/05/vbnet-tutorial-sql-database-basics.html

-- EDIT --

Now that you're connecting to the database, it will be easiest for you to use one of the built in ASP.Net controls to display the results of your query on your web page. The easiest way to do this will be with a "GridView" control... here's another tutorial that should get you up and running...

http://www.devx.com/dotnet/Article/22141

Related Question