我有个借阅程序,当图号一样的只剩下一本时,禁止出库。但是我程序写了剩下一本时还是可以出库,看不出有什么问题,希望各位大虾指教下,感激感激
    string sbth2 = this.TextBox25.Text;
    string th2 = this.TextBox11.Text;        string fs = "";
        string SqlConn4 = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
        SqlConnection Conn4 = new SqlConnection(SqlConn4);
        Conn4.Open();
        string SqlStr4 = "select sum(dqsl) as fs1 from sb_cktz where sbth='" + sbth2 + "' and th='" + th2 + "' ";
        SqlCommand Comm4 = new SqlCommand(SqlStr4, Conn4);
        SqlDataReader read4 = Comm4.ExecuteReader();
        read4.Read();
        fs = read4["fs1"].ToString();
        if (fs == "1")
        {
            this.RegisterStartupScript("提示", " <script language=\"javascript\"> alert('该资料只剩下最后一套,不能借阅!'); </script> ");
            read4.Close();
            Conn4.Close();
            return;        }

解决方案 »

  1.   

    业务和前台没分开的? ClientScript.RegisterStartupScript(GetType(), "", "<Script Language=JavaScript>alert(\"该资料只剩下最后一套,不能借阅!\")</Script>");自己跟踪一下,看看fs到底为多少
    Comm4.ExecuteReader();只有一条记录,则用scaler好点吧.
      

  2.   

    select count(*) from Tb where 条件
    为1 ClientScript.RegisterStartupScript
    return;
      

  3.   

    fs = read4["fs1"].ToString();  这样的话如果读出来的是空值怎么办?
      

  4.   


    if(read4.Read())
    {
       .....
    }