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>
<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
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>
<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