The Better Way is——
public int Dg() {
OleDbCommand myCmd = new OleDbCommand("select count(*) from screcord",myConn);
int c=int.Parse(myCmd.ExecuteScalar().ToString());
return(c);

解决方案 »

  1.   

    Agree.int c = System.Convert.ToInt32(myCmd.ExecuteScalar());
      

  2.   

    string sql="select count(*) from screcord";
    SqlCommand myCmd = new SqlCommand ("select count(*) from screcord",myConn);
    myConn.open();
    SqlDataReader MyReader=myCmd.ExecuteReader();
    int c=myCmd.GetInt32(0);
      

  3.   

    错!!!了!!!
    最后一句改为:
    int c=MyReader.GetInt32(0);
      

  4.   

    int count=0;
    SqlCommand myCommand = new SqlCommand("select count(*) from bbs1", myConnection);
    myConnection.Open();
    SqlDataReader reader = myCommand.ExecuteReader();
    while(reader.Read())
    {
      count = (int)reader[0];
    }