解决方案 »

  1.   

    这样写不对吗? string strCon ="Data Source=(local);DataBase=kaoshi;User id=sa;pwd=123";
           SqlConnection con = new SqlConnection(strCon);
            con.Open();
            int count1=0;
            int count2=0;
            SqlCommand mycom1= new SqlCommand("select * from chengji where StudentID="+  Application["StudentID"]+"and LessonID=01",con);
            SqlCommand mycom2= new SqlCommand("select * from chengji where StudentID="+  Application["StudentID"]+"and LessonID=02",con);
            count1= Convert.ToInt32(mycom1.ExecuteScalar());
            count2= Convert.ToInt32(mycom2.ExecuteScalar());
            Label1.Text=count1.ToString();
            Label2.Text=count2.ToString();
      

  2.   

    count1= mycom1.ExecuteNonQuery();试试这样取
      

  3.   

    ExecuteScalar()这是返回结果集首行首列的值,跟你问的影响的行数不搭边!
      

  4.   

    using (SqlConnection sqlcon = new SqlConnection(strcon))
                {
                    sqlcon.Open();
                    using (SqlCommand comm = new SqlCommand(sql, sqlcon))
                    {
                        comm.Parameters.Clear();
                        if (sqlparam != null)
                        {
                            comm.Parameters.AddRange(sqlparam);
                        }
                        return comm.ExecuteNonQuery();
                    }
                }comm.ExecuteNonQuery();就是返回影响行数        
    存储过程里面可以用@@ROWCOUNT获得受影响的行数。
      

  5.   


    ExecuteScalar是得出查询结果的第一行第一列的内容 
      

  6.   

    你是读数据用ExecuteReader【数据的读】,一条一条取出数据。
    ExecuteScalar是用来读一列【数据的读】
    ExecuteNonQuery是用来返回受影响的行数【数据的增、删、改】
      

  7.   

    查询多少行数可以直接Count(*) ExecuteScalar()