-1

Good day!, I want to retrieve data from my database the user will input in the text box and when the user click the search button it will display in the form but when I execute the code below nothing will happen. Can anyone help me.

    namespace booksreviews
    {
    public partial class search : System.Web.UI.Page
    {
    private SqlConnection connection;
    private SqlCommand command;
    private int count = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
       SqlConnection Con = new SqlConnection("connectionstring");


    }
    public  SqlConnection con { get; set; }

    protected void btnSearch_Click(object sender, EventArgs e)
    {

       try{
       con.Open()
        int result = command.ExecuteNonQuery();
        if (txtTitle.Text == string.Empty)
    {
    SqlCommand cmd = new SqlCommand("
    Select                                                                
    title,authors,publisher,price,nopages,pubdate from book ", con);
    }
    else
    {
    SqlCommand cmd = new SqlCommand("
    select title,authors,publisher,price,nopages,pubdate from book where
     id= '" +  txtTitle.Text + "'", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    dlBooks.DataSource = ds;
    dlBooks.DataBind();
}catch (ArgumentException argumentEx)
    {
        Response.Write(argumentEx.Message);
    }
    catch (SqlException ex)
    {
        Response.Write(ex.Message);
    }
    catch (IndexOutOfRangeException bound)
    {
        Response.Write(bound.Message);
    }
    finally
    {
        connection.Close();
    }
         }
    }
    }
    }
user3278908
  • 445
  • 1
  • 4
  • 8

1 Answers1

0

If you click button but nothing happens, it's highly possible that you didn't hook up your event handler with the button control, otherwise at least the yellow page will come out.

Eric.Y.Fan
  • 236
  • 1
  • 5