public partial class Welcome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("Login.aspx");
            }
        }        protected void Btreseach_Click(object sender, EventArgs e)
        {
            string s = System.Configuration.ConfigurationManager.ConnectionStrings["LibraryManageSystem"].ToString();
            SqlConnection conn = new SqlConnection(s);
            string sqlstr = "select * from Book where bname=@name";
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn ;
            comm.CommandText = sqlstr;
            comm.Parameters.AddWithValue("@name", Tbname.Text);
            try
            {
                conn.Open();
                SqlDataReader dr = comm.ExecuteReader();
                if (dr.Read())
                {
                    GridView1.DataSource = dr;
                    GridView1.DataBind();
                }
                else { Response.Write("<script>alert('查询失败')</script>"); }
            }
            catch (SqlException ex)
            {
                Response.Write(ex.Message);
            }            finally
            {
                conn.Close();
            } 
        }    }