数据库:   ID      Stud_no    Stud_course1
自动编号       123           (空值)===============================================================================================
  public static bool insert(string que) //在类adm下的函数
    { //根据传进来的SQL语句执行插入/删除/更新等操作
        OleDbConnection con = adm.con();
        con.Open();
        OleDbCommand cmd = new OleDbCommand(que, con);
        int count = Convert.ToInt32(cmd.ExecuteNonQuery());
        if (count > 0)
        {
            con.Close();
            return true;
        }
        else
        {
            con.Close();
            return false;
        }
============================================================================================  string aaa = "123";        bool back = adm.insert("update student set Stud_course1 = '" + idd + "' where Stud_course1='' and Stud_no='" + aaa + "'");        if (back)
            Response.Write("<script>alert('添加成功!');</script>");按理说我运行之后back=ture也就是count要>0,可是为什么count=0
?????
帮忙一下,在线等待!!!!

解决方案 »

  1.   

    (Stud_course1='' or Stud_course1 is null) ?
      

  2.   

    什么意思啊!back==true那肯定count>0了
    你从哪里看到的count值呢?
      

  3.   

    楼上的,count 在类adm里,count的值是从Convert.ToInt32(cmd.ExecuteNonQuery()); 这里得到的,返回响影的记录数,back是个bool类型的变量,如果count>0那back的值要等于true
      

  4.   

    ExecuteNonQuery()这个方法不会返回影响的行数,返回值永远是-1,换成Execute()看看
      

  5.   

    楼上的,没有你说的那个Execute(),还有,我另外一个代码也是update的,都有返回影响行数的.可我看不出这个SQL语句有什么错啊!
      

  6.   

    那能错的也只有sql语句了,where Stud_course1=''换成 where ISNULL(Stud_course1,'') 看看呢
      

  7.   

    update student set Stud_course1 = '" + idd + "' where ISNULL(Stud_course1)and Stud_no='" + aaa + "'"); 他说句法错误
      

  8.   

    update student set Stud_course1 = '" + idd + "' where ISNULL(Stud_course1) and Stud_no='" + aaa + "'");  不如这样写
    OledbCommand cmd=new OledbCommand("update update student set Stud_course1=@id where
    Stud_course1 is null and stud_no=@no");OledbParameter[] params=new OledbParameter[]{new OledbParameter("@id",SqlDbType.varchar), 
    new OledbParameter("@no",SqlDbType.varchar), }params[0].value="";
    params[1].value="";cmd.Parameter.add(params);
    cmd.ExecuteNoQuery();
    大概这个意思。代码可能不对,懒得开studio了
      

  9.   

    好像忘记和你说了 update student set Stud_course1 = '" + idd + "' where ISNULL(Stud_course1) 空格and Stud_no='" + aaa + "'");  
      

  10.   

    测试sql语句对不对最好用查询分析器。
    一处是空格的问题
    一个是isnull的问题吧
    建议用 
    Stud_course1 is null and studion=''
      

  11.   

    update student set Stud_course1 = '" + idd + "' where (Stud_course1 is null or Stud_course1 = '') and Stud_no='" + aaa + "'";
    这样还不行的话 那就去到数据库
    set nocount off            ---(ms Sql)
      

  12.   

    lz不明白我的意思么,ISNULL不是这么写的,唉,我的意思是可能你这个字段里面填的是null值,但是你拿来和‘’字符串空比较所以建议你转化以下
    我帮你写吧:
    string sql="update student set Stud_course1 = '" + idd + "' where ISNULL(Stud_course1,'')='' and Stud_no='" + aaa + "'";