string SQL = "select count(*) from abc where id=1";
OleDbConnection Myconn = new OleDbConnection(MyConnString);
OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
Mycomm.Connection.Open();
OleDbDataReader dr = Mycomm.ExecuteReader();
1.我想获得id为1的记录的数量,接下来程序里该怎么写呢?万分感谢!

解决方案 »

  1.   

    string SQL = "select count(*) from abc where id=1";
    OleDbConnection Myconn = new OleDbConnection(MyConnString);
    OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
    Mycomm.Connection.Open();
    OleDbDataReader dr = Mycomm.ExecuteReader();if(dr.Read())
    {
       int tmp = Convert.ToInt32(dr[0]);
    }
      

  2.   

    ??SQL中是几,id为1的数量就有几呀,这还要怎么写??
      

  3.   

    int count;
    string SQL = "select count(*) from abc where id=1";
    OleDbConnection Myconn = new OleDbConnection(MyConnString);
    OleDbCommand Mycomm = new OleDbCommand(SQL,Myconn);
    Mycomm.Connection.Open();
    count= Mycomm.ExecuteScalar();
    这样执行效率要高,而且获取就一个值。
      

  4.   

    我按楼上的朋友说的试过了不行,executeScalar()返回的是object。
    如何才能获得select count(*) from abc where id=1的记录数量阿?
      

  5.   

    string str = "select max(xx) from xxx";
    SqlCommand myCommand = new SqlCommand();
    myCommand.Connection = yourconnection;
    myCommand.CommandType = CommandType.Text;
    myCommand.CommandText = str;
    myCommand.Connection.Close();
    myCommand.Connection.Open();
    string num = myCommand.ExecuteScalar().ToString();
    Page.RegisterStartupScript("check", "<script>alert('记录数量为+num');</script>");
      

  6.   

    写错了一个
    那个string str = "select max(xx) from xxx";
    是 string str = "select count(xx) from xxx";
      

  7.   

    谢谢,请问count(xx)里的xx代表什么?
      

  8.   

    字符串改为:string SQL = "select CountA=count(*) from abc where id=1";
    然后在结果集里取值
      

  9.   

    int id= dr.FieldCount();
    这个是不是哦?????