ASP.NET(c#)查询问题。

来源:百度知道 编辑:UC知道 时间:2024/06/24 15:49:05
public partial class _Default : System.Web.UI.Page
{
public void bind()
{
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conStr1"]);
strcon.Open();
string strsql = "select * from T_Kehuxinxi where 1=1 " + Session["Sqll"] + " ";
SqlDataAdapter sda = new SqlDataAdapter(strsql, strcon);
DataSet ds = new DataSet();
sda.Fill(ds, "shengri");
GridView1.DataSource = ds.Tables["shengri"];
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataBind();
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
strin

看你的意思大概是 不定条件查询吧, 如果是 可以到 本人空间逛逛 ,前几天弄了个不定条件查询。不明白地方可以 加我 baiduhi:ayqinhui 如果没有可以给我留言, 每天定时查看的。
如果说不是,估计是我理解错误!

看你的代码,觉得没必要将sql语句存储在Session会话对象中。现在时间紧有空帮你改改

在前面SQL定义的时候改成这样string sql = " 1=1 ";然后其他的跟你的一样就好了.