Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. return number of records selected

return number of records selected

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdul Rhman Alsri
    wrote on last edited by
    #1

    how to get number of records selected?

    SqlDataReader dr1 = cmd1.ExecuteReader();

    D U L S A 5 Replies Last reply
    0
    • A Abdul Rhman Alsri

      how to get number of records selected?

      SqlDataReader dr1 = cmd1.ExecuteReader();

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      I don't think you can tell ahead of time how many records will be returned. If you need to know that, then you can use a COUNT function in your SQL or loop through the records and count them as you go.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      1 Reply Last reply
      0
      • A Abdul Rhman Alsri

        how to get number of records selected?

        SqlDataReader dr1 = cmd1.ExecuteReader();

        U Offline
        U Offline
        User 4167136
        wrote on last edited by
        #3

        The other way will be to use a dataset and do a count of that dataset: SqlDataAdapter sqldataadap = new SqlDataAdapter(objCmd); //objCmd is your Sql Command Object DataSet ds = new DataSet(); sqldataadap.Fill(ds); //get the # of rows: int irow=ds.Tables[0].Rows.Count;

        1 Reply Last reply
        0
        • A Abdul Rhman Alsri

          how to get number of records selected?

          SqlDataReader dr1 = cmd1.ExecuteReader();

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          After running any type of query just fire following query to know number of rows affected.

          SELECT @@rowcount AS 'RowsChanged'

          Hope this will help!

          Jinal Desai - LIVE Experience is mother of sage....

          1 Reply Last reply
          0
          • A Abdul Rhman Alsri

            how to get number of records selected?

            SqlDataReader dr1 = cmd1.ExecuteReader();

            S Offline
            S Offline
            Saiyed Alam
            wrote on last edited by
            #5

            Fill a data adapter with a dataset. Then count the rows. Some thing like: int totalRow = Dataset.Tables[0].Rows.Count;

            1 Reply Last reply
            0
            • A Abdul Rhman Alsri

              how to get number of records selected?

              SqlDataReader dr1 = cmd1.ExecuteReader();

              A Offline
              A Offline
              Abhinav S
              wrote on last edited by
              #6

              The reader does not have a count. You could however use an ExecuteScalar to get the count. int i = (int)cmd1.ExecuteScalar();

              J 1 Reply Last reply
              0
              • A Abhinav S

                The reader does not have a count. You could however use an ExecuteScalar to get the count. int i = (int)cmd1.ExecuteScalar();

                J Offline
                J Offline
                Johnny J
                wrote on last edited by
                #7

                How exactly do you reckon this will return the row count? What is cmd1.CommandText in this case?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups