做工资系统,查看某个人的工资详细项,我放了一个输入文本框,然后在后面放了一个查询按钮,希望点了按钮以后按照文本框里的关键字查询并且直接显示到detailsview里,要怎么做?
我现在的代码是这样的    <div><asp:Label ID="label1" runat="server" Text="员工编号:"></asp:Label>
      <asp:TextBox ID="empcode_input" runat="server"></asp:TextBox>
      <asp:Button ID="checkpay" runat="server" Text="查看" onclick="checkpay_Click" /></div>
    <div><br /><asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px">
    </asp:DetailsView></div>程序代码:    private DataView mn;
    protected void checkpay_Click(object sender, EventArgs e)
    {
        string sqlconn = "Data Source=WIN-VM5GVPGG2R3;Initial Catalog=laborage;Integrated Security=True";
        SqlConnection myConn = new SqlConnection(sqlconn);
        myConn.Open();
        SqlCommand myComm = new SqlCommand("SELECT * FROM [ATTENDENCE] where EMPCODE=" + empcode_input.Text.Trim(), myConn);
        SqlDataAdapter myAdapter = new SqlDataAdapter();
        myAdapter.SelectCommand = myComm;
        DataSet myDs = new DataSet();
        myAdapter.Fill(myDs);
        mn = myDs.Tables[0].DefaultView;
        myConn.Close();
        this.DetailsView1.DataSource = mn;
        this.DetailsView1.DataBind();
    }运行以后点了查看按钮就报错了,说 '=' 附近有语法错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: '=' 附近有语法错误。源错误: 
行 32:         myAdapter.SelectCommand = myComm;
行 33:         DataSet myDs = new DataSet();
行 34:         myAdapter.Fill(myDs);
行 35:         mn = myDs.Tables[0].DefaultView;
行 36:         myConn.Close();
 谁教我一个正确的做法呀?这个我不懂,乱搬的……

解决方案 »

  1.   

    SqlCommand myComm = new SqlCommand("SELECT * FROM [ATTENDENCE] where EMPCODE=" + empcode_input.Text.Trim(), myConn);
    这句不对吧改成SqlCommand myComm = new SqlCommand("SELECT * FROM [ATTENDENCE] where EMPCODE='" + empcode_input.Text.Trim() + "' ", myConn);
    看看
      

  2.   

    疯了……再次犯了低级错误……
    这个代码是我用书上一段gridview的载入代码改的,还以为是代码本身不对呢
    谢谢!