Web search in SQL database

S

Stefano B*

I try to create a search engigne to query a SQL database. I use asp.net with
c#, but i have some problems. I want my users insert whatever they want in
the TextBox. This is my code:

HTML
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
&nbsp;&nbsp;
<asp:Button id="Button2" onclick="query_click" runat="server"
Text="Button"></asp:Button>

<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="true">
<HeaderStyle font-bold="True" forecolor="white"
backcolor="#4A3C8C"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>

CODE:
void query_click (Object sender, EventArgs e) {

string ConnectionString =
"server=(local);database=prova;trusted_connection=true";
string CommandText;

SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand(CommandText, myConnection);
CommandText = "select * from film where titolo LIKE '%" + keywords +
"%'";
myConnection.Open();

DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataBind();

Doesn't works!

Bye
Stefano from Italy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top