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);
public int Dg() {
OleDbCommand myCmd = new OleDbCommand("select count(*) from screcord",myConn);
int c=int.Parse(myCmd.ExecuteScalar().ToString());
return(c);
SqlCommand myCmd = new SqlCommand ("select count(*) from screcord",myConn);
myConn.open();
SqlDataReader MyReader=myCmd.ExecuteReader();
int c=myCmd.GetInt32(0);
最后一句改为:
int c=MyReader.GetInt32(0);
SqlCommand myCommand = new SqlCommand("select count(*) from bbs1", myConnection);
myConnection.Open();
SqlDataReader reader = myCommand.ExecuteReader();
while(reader.Read())
{
count = (int)reader[0];
}