我是一个初学者~我想将我的查询结果显示在gridview中~执行一次查询就将查询结果显示在gridview中请问该如何进行操作~如何编写代码
   以下是我写的查询的代码~
  
   protected void Button1_Click(object sender, EventArgs e)
    {
        string mystr= "Server=(local);User Id=sa;Pwd=;DataBase=gl";
        SqlConnection my = new SqlConnection(mystr);
        if (CheckBox1.Checked == true)
        { string stra = @"select idbn,name,press,writer,mon,num,zk from btable where isbn=" + TextBox1.Text + "";
        
    }
        else if (CheckBox2.Checked == true)
        { string strb = @"select isbn,name,press,writer,mon,num,zk from btable where name=" + TextBox1.Text + "";
        
    }
        else { string strc = @"select isbn,name,press,writer,mon,num,zk from btable";
        
    }
        my.Close();
    }
     谢谢大家~

解决方案 »

  1.   

    真BT
    Google ADO.NET的几个对象
    再Google GridView
      

  2.   

    用数据适配器填充数据表,或者用数据阅读器,然后跟GridView绑定就可以了。
    SqlDataAdapter da=new SqlDataAdapter("sql查询语句",my);
    DataTable dt=new DataTable();
    da.Fill(dt);
    .....
    GridView1.DataSource=dt;
    GridView1.DataBind();另外你的sql语句是错误的,应该改成"......where isbn='" + TextBox1.Text + "'"
    其他也要加单引号,因为这个字段的值是字符串型的。最好用参数化查询,可以有效避免sql注入风险。