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();
}
}
}
}
}