SqlConnection con  = new SqlConnection("server=(local);uid=sa;pwd=sa;database=tttttt");

SqlDataAdapter sap = new SqlDataAdapter();
sap.SelectCommand = new SqlCommand("select * from inf_county");
sap.SelectCommand.Connection = con; DataSet ds = new DataSet(); sap.Fill(ds); ds.Tables[0].Rows.Count就是了

解决方案 »

  1.   

    string m_ConnStr = "data source=127.0.0.1;database=pubs;user id=sa;password=sa";
    SqlConnection m_Conn = new SqlConnection(m_ConnStr);

    SqlDataAdapter m_Da = new SqlDataAdapter("select title from titles",m_Conn); DataSet m_Ds = new DataSet();
    m_Da.Fill(m_Ds); int i = m_Ds.Tables["Titles"].Rows.Count );   //i返回结果集的行数
      

  2.   

    int i = m_Ds.Tables["Titles"].Rows.Count;   //i返回结果集的行数
      

  3.   

    送你一个东西吧:
    public int GetRsCount(string table_name)
    {
    string strSql;
    int intCount;
    Open();
    strSql="select count(*) from "+table_name;
    SqlCommand cmd=new SqlCommand(strSql,cn);
    intCount=(int)cmd.ExecuteScalar();
    Close();
    return intCount;
    }
      

  4.   

    SqlCom.CommandText="select count(*) from A; select * from A";
    ......
    SqlDataReader myReader=SqlCom.ExcuteReader();
    int iCount=0;
    if (myReader.Read())
    {
      iCount=myReader.GetInt32(0);//返回记录数
    }
    利用iCount大小声明数组
    myReader.NextResult();
    while (myReader.Read())
    {
    读取记录到数组
    }
      

  5.   

    /   .
                                                              ' /  .- .
                                                              .  .- .-
                                                            ./    .--...
                                                  .-------- 0    .--
                                                 /                 .......
                                                '                  ..
                                                 '........            ----
                                                          .          --..
                                                           .   .---..   -
                                       分  o               .  '     -.
                                         分               /   '
                                                         / ' ' '
                                       \-分--/....... . '  ' '  '
                                        \ __/ -      - -'  '  ' '
                                                        '  '  ' '
                                         o              '   ' ' '
                                                        '   '  '
                                                         -..'.----------.
                                                            I   ----------
                                                     /////////.
      

  6.   

    我想这个可能是你想要的吧:
    SqlConnection con = new ("联接字符串");
    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "select * from A";
    int count = cmd.ExecuteNonQuery();// Object count = cmd.ExecuteScalar();(语句2)
    语句2 用来和这们的语句配合的:select count(*) from A
    count就是你想要的行数!
      

  7.   

    上边的少写了一个cmd.Close();
    ExecuteNonQuery()返回所影响的行数,但不返回任何结果 
    ExcuteScalar()要返回结果的,这样我想你应该明白了吧!