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. ExecuteNonQuery or using a dataset?

ExecuteNonQuery or using a dataset?

Scheduled Pinned Locked Moved C#
databasehelpquestion
4 Posts 3 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.
  • F Offline
    F Offline
    Forrest Feather
    wrote on last edited by
    #1

    When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!

    M C 2 Replies Last reply
    0
    • F Forrest Feather

      When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      DataSet is for when you want to many more things than that , if you want one time access , one record returned use ExecuteNonQuery . Use Dataset when you want disconnected many insert/update/delete/read from your database. Mazy "Man is different from animals in that he speculates, a high risk activity." - Edward Hoagland

      1 Reply Last reply
      0
      • F Forrest Feather

        When i want query in a database for some data... I find there's two ways. the first one is give a definition of selectcommand,then ExecuteNonQuery. Sometimes we use dataset.. Is there any distinctions of these two ways? thanks for help!

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        :confused: ExecuteNonQuery will not return any data. :confused: How can you execute a query with ExecuteNonQuery? That is for maintenance or updata/insert/delete tasks when you don't need a result back from the database. ExecuteDataReader or ExecuteScalar do return data. The former returns a Data Reader object which you can use to access the records, and the latter returns a single value (If your query generates more than one value the single value returned will be the first field on the first row) If you are using a dataset you can disconnect from the data source - This is useful for mobile applications, for instance. With a dataset you copy the data into your application and work on the copy (this increases the memory overhead). A rule-of-thumb that I use is that if the data is a one-time use or I will be constantly connected to the database I use a data reader. If I am going to disconnect from the database I use a dataset. In general I prefer to use a data reader because the memory overhead is less and often it is faster to send a query to the database than filter an existing dataset because the database is designed to be queried efficiently, a dataset it not. Does this help?


        "You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar

        F 1 Reply Last reply
        0
        • C Colin Angus Mackay

          :confused: ExecuteNonQuery will not return any data. :confused: How can you execute a query with ExecuteNonQuery? That is for maintenance or updata/insert/delete tasks when you don't need a result back from the database. ExecuteDataReader or ExecuteScalar do return data. The former returns a Data Reader object which you can use to access the records, and the latter returns a single value (If your query generates more than one value the single value returned will be the first field on the first row) If you are using a dataset you can disconnect from the data source - This is useful for mobile applications, for instance. With a dataset you copy the data into your application and work on the copy (this increases the memory overhead). A rule-of-thumb that I use is that if the data is a one-time use or I will be constantly connected to the database I use a data reader. If I am going to disconnect from the database I use a dataset. In general I prefer to use a data reader because the memory overhead is less and often it is faster to send a query to the database than filter an existing dataset because the database is designed to be queried efficiently, a dataset it not. Does this help?


          "You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar

          F Offline
          F Offline
          Forrest Feather
          wrote on last edited by
          #4

          Thanks for your particular answer:) It helps me a lot:)

          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