以下是后台代码,前台是按编号和姓名来查询自己的工资,当我单击前台查询的时候,为什么没有数据显示出来的?只是显示没有权限或输入错误?请问是错在哪里 了?谢谢~~using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class user_usersalary : System.Web.UI.Page
{
    public void bind()
    {
        string strsql;
        if (this.TextBox2.Text != "")
        {
            strsql = "select bianhao,realname,empl_pays,empl_zcpay,empl_age,empl_zw,empl_bufa,empl_jt,empl_hsf,empl_flj,empl_jbf,empl_ydf,empl_jj,empl_other,empl_qq,empl_lbf,empl_bxf,empl_cf,empl_jzkh,empl_sds,empl_ykgz,empl_sfgz,empl_info from rs_salary where realname='" + this.TextBox2.Text + "'and level='一般用户'and username='" + Convert.ToString(Session["username"]) + "'";
        }
        else if (this.TextBox1.Text != "")
        {
            strsql = "select bianhao,realname,empl_pays,empl_zcpay,empl_age,empl_zw,empl_bufa,empl_jt,empl_hsf,empl_flj,empl_jbf,empl_ydf,empl_jj,empl_other,empl_qq,empl_lbf,empl_bxf,empl_cf,empl_jzkh,empl_sds,empl_ykgz,empl_sfgz,empl_info from rs_salary where bianhao='" + this.TextBox1.Text + "'and level='一般用户'and username='" + Convert.ToString(Session["username"]) + "'";
        }
        else
        {
            Response.Write("<script>alert('您没有权限或输入错误!');history.back()</script>");
            return;
        }
        SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        strcon.Open();
        SqlDataAdapter sda = new SqlDataAdapter(strsql, strcon);
        DataSet ds = new DataSet();
        sda.Fill(ds, "rs_salary");
        GV.DataSource = ds.Tables["rs_salary"];
        GV.DataBind();
    }
    public void bd()
    {
        string sql = "select bianhao,realname,empl_pays,empl_zcpay,empl_age,empl_zw,empl_bufa,empl_jt,empl_hsf,empl_flj,empl_jbf,empl_ydf,empl_jj,empl_other,empl_qq,empl_lbf,empl_bxf,empl_cf,empl_jzkh,empl_sds,empl_ykgz,empl_sfgz,empl_info from rs_salary ";
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "gzcx");
        GV.DataSource = ds.Tables["gzcx"];
        GV.DataBind();
        con.Close();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.TextBox1.Focus();
            this.TextBox1.Text = "";            
        }
    }
    protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GV.PageIndex = e.NewPageIndex;
        this.bd();
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        this.bind();
        this.TextBox1.Text = "";
        this.TextBox2.Text = "";
    }
}

解决方案 »

  1.   

    if (this.TextBox2.Text != "")
      {
      strsql = "select bianhao,realname,empl_pays,empl_zcpay,empl_age,empl_zw,empl_bufa,empl_jt,empl_hsf,empl_flj,empl_jbf,empl_ydf,empl_jj,empl_other,empl_qq,empl_lbf,empl_bxf,empl_cf,empl_jzkh,empl_sds,empl_ykgz,empl_sfgz,empl_info from rs_salary where realname='" + this.TextBox2.Text + "'and level='一般用户'and username='" + Convert.ToString(Session["username"]) + "'";
    //绑定
      }
      else if (this.TextBox1.Text != "")
      {
      strsql = "select bianhao,realname,empl_pays,empl_zcpay,empl_age,empl_zw,empl_bufa,empl_jt,empl_hsf,empl_flj,empl_jbf,empl_ydf,empl_jj,empl_other,empl_qq,empl_lbf,empl_bxf,empl_cf,empl_jzkh,empl_sds,empl_ykgz,empl_sfgz,empl_info from rs_salary where bianhao='" + this.TextBox1.Text + "'and level='一般用户'and username='" + Convert.ToString(Session["username"]) + "'";
    //绑定
      }
      else
      {
      Response.Write("<script>alert('您没有权限或输入错误!');history.back()</script>");
      }
      

  2.   

    又长,又没有文字说明,还拼写SQL,又没有分层。眼花了