Web search in SQL database

Discussion in 'ASP .Net Web Services' started by Stefano B*, Oct 5, 2004.

  1. Stefano B*

    Stefano B* Guest

    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
    Stefano B*, Oct 5, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul M

    SQL database table ot SQL schema

    Paul M, Dec 8, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    410
    Mythran
    Dec 8, 2003
  2. Replies:
    2
    Views:
    4,279
  3. Keith
    Replies:
    1
    Views:
    2,322
    Keith
    Jul 3, 2006
  4. Bill

    SQL Statements in a Database Search

    Bill, Jul 15, 2003, in forum: ASP General
    Replies:
    2
    Views:
    85
    Bob Barrows
    Jul 15, 2003
  5. Abby Lee
    Replies:
    5
    Views:
    400
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page