SqlConnection myCon;
        myCon = new SqlConnection("data source=localhost;initial catalog=hotel;user id=sa;password=123");
        string sql2 = "update room set status = '入住' where roomId = '" + roomId + "'";
        SqlCommand myCom = new SqlCommand(sql2, myCon);
        myCon.Open();
        SqlDataReader Reader;
        Reader = myCom.ExecuteReader();status数据类型为VARCHAR,不清楚为什么会错误

解决方案 »

  1.   

    roomId 如果是int型,改成string sql2 = "update room set status = '入住' where roomId = " + roomId; 
      

  2.   

    roomId 是char类型,2楼的改了也不行。。
      

  3.   

    明明是更新操作,为什么要用ExecuteReader,这是用于select的嘛。。
    按照2楼说的,改为ExecuteNoQuery,
      

  4.   

    错误提示是什么?应该和是否为ExecuteReader无关
      

  5.   

    string sql2=string.format("update room set status = {0} where roomId ={1}","入住",roomId.toString());
      

  6.   


    string sql2 = string.Format("update room set status = '入住' where roomId = '{0}' ", roomId);
      

  7.   

    在SQl 中能够将varchar 转为int 吗?
      

  8.   

      string sql2 = "update room set status = '入住' where roomId =" + roomId + ""; 
     SqlCommand myCom = new SqlCommand(sql2, myCon); 
       myCon.Open(); 
       int affectrows=myCom.ExecuteNonQuery();
      

  9.   

    lz的status 字段类型为Int,怎么能用status = '入住' 呢
    应该先用c#进行转换,
    int status = 0;
    if(txtStatus.text == '入住')  status = 1 
    else status = 0然后再用 
        string sql2 = "update room set status = " +  status + " where roomId = '" + roomId + "'"; 
      

  10.   

    调试一下   进了断点   把sql2的语句取出来放到查询分析器里面看看有没有错
    有错的话就检查一下语句
    没错的话可能就是如2楼的改法了