本帖最后由 Wasserkoenig 于 2010-04-03 11:45:41 编辑

解决方案 »

  1.   

    string medicarenumberCount = "select count(*) from medicare where name = " + textBoxName +"";
    //SQL执行语句呢?
      if ( Int32.Parse(medicarenumberCount) >= 1 )  //多半情况是medicarenumberCount为空,可以设断点跟踪一下string medicarenumberCount的值  {
      strErrorMsg.Append("非常抱歉,这位患者已经享受过医保优惠!\n");
      }
      

  2.   

    谢谢kaiyong! 原因是medicarenumberCount为空。string medicarenumberCount = "select count(*) from medicare where name = " + textBoxName +"";
    这一行没有真正执行。SQL执行语句怎么写? 请指教谢谢。
      

  3.   

    select count(*) from medicare where name = " + textBoxName +"这一句不就是SQL执行语句么?
      

  4.   

    string medicarenumberCount = "select count(*) from medicare where name ='" + textBoxName +"'";
      

  5.   

    " + textBoxName +" 两侧加上单引号,还是同样的问题。
      

  6.   

    1. 你的老师没有教你用参数化的语句么?拼接sql语句这种写法就不合理
    2. 如果textBoxName 是一个文本框的话,应该是textBoxName.Textstring medicarenumberCount = "select count(*) from medicare where name ='" + textBoxName.Text +"'";
      

  7.   


    谢谢你的提醒,是我太大意了,但是我改了一下,还是同样的错误。
    string tB = textBoxName.Text;
                string medicarenumberCount = "select count(*) from medicare where name = '"+tB+"'";
                if ( Int32.Parse(medicarenumberCount) >= 1 )
                {
                    strErrorMsg.Append("非常抱歉,这位患者已经享受过医保优惠!\n");
                }