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. Visual Basic
  4. Diff betn ExecuteNonQuery & ExecuteScalar

Diff betn ExecuteNonQuery & ExecuteScalar

Scheduled Pinned Locked Moved Visual Basic
7 Posts 2 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.
  • M Offline
    M Offline
    mayhem_rules
    wrote on last edited by
    #1

    Hello Guys, Can anyone tell me the difference between ExecuteNonQuery & ExecuteScalar. Also, in what cases should one use ExecuteNonQuery & ExecuteScalar. With Best Regards, Mayur

    N 1 Reply Last reply
    0
    • M mayhem_rules

      Hello Guys, Can anyone tell me the difference between ExecuteNonQuery & ExecuteScalar. Also, in what cases should one use ExecuteNonQuery & ExecuteScalar. With Best Regards, Mayur

      N Offline
      N Offline
      ne0h
      wrote on last edited by
      #2

      use ExecuteScaler when u need to get only one value from DB(i.e. when u're using aggregate func) and use ExecuteNonQuery when u need to insert/update/delete operation. e.g if ur query is "SELECT AVG(sal) FROM MyTable" then use ExecuteScaler, because it returns only one value. this is not the end, this is how its goin to begin !

      M 1 Reply Last reply
      0
      • N ne0h

        use ExecuteScaler when u need to get only one value from DB(i.e. when u're using aggregate func) and use ExecuteNonQuery when u need to insert/update/delete operation. e.g if ur query is "SELECT AVG(sal) FROM MyTable" then use ExecuteScaler, because it returns only one value. this is not the end, this is how its goin to begin !

        M Offline
        M Offline
        mayhem_rules
        wrote on last edited by
        #3

        considering your eg. if i need to obtain the avg(sal) of emp from a table group by department, then will i get several records as per the departments if i use executescalar. thnx for your reply. With Best Regards, Mayur

        N 1 Reply Last reply
        0
        • M mayhem_rules

          considering your eg. if i need to obtain the avg(sal) of emp from a table group by department, then will i get several records as per the departments if i use executescalar. thnx for your reply. With Best Regards, Mayur

          N Offline
          N Offline
          ne0h
          wrote on last edited by
          #4

          then u cant use ExecuteScaler in dat case. or u can use ExecuteScaler but it'll return the first value returned by SQL Query...its only for one value... this is not the end, this is how its goin to begin !

          M 1 Reply Last reply
          0
          • N ne0h

            then u cant use ExecuteScaler in dat case. or u can use ExecuteScaler but it'll return the first value returned by SQL Query...its only for one value... this is not the end, this is how its goin to begin !

            M Offline
            M Offline
            mayhem_rules
            wrote on last edited by
            #5

            ok thnx a lot. also i noticed 'ExecuteReader'. Any idea about it. Also, i need to know whether there is any way where I insert/update/delete records to the datatable and reflect all changes to the database in the end. My current operation is taking a lot of time to execute each insert/update/delete statement. With Best Regards, Mayur -- modified at 4:17 Wednesday 22nd February, 2006

            N 1 Reply Last reply
            0
            • M mayhem_rules

              ok thnx a lot. also i noticed 'ExecuteReader'. Any idea about it. Also, i need to know whether there is any way where I insert/update/delete records to the datatable and reflect all changes to the database in the end. My current operation is taking a lot of time to execute each insert/update/delete statement. With Best Regards, Mayur -- modified at 4:17 Wednesday 22nd February, 2006

              N Offline
              N Offline
              ne0h
              wrote on last edited by
              #6

              ExecuteReader used in simple database read operation to populate SQLDataReader with ur query...like // some code Dim dr As SQLDataReader=cmd.ExecuteReader while( dr.Read() ) // get values using dr.GetValue(0) End While as of ur 2nd question, i need chk out n will post here later, becoz i forgot the code ...all i can say is updation of DB from DataTable is ALWAYS possible. this is not the end, this is how its goin to begin !

              M 1 Reply Last reply
              0
              • N ne0h

                ExecuteReader used in simple database read operation to populate SQLDataReader with ur query...like // some code Dim dr As SQLDataReader=cmd.ExecuteReader while( dr.Read() ) // get values using dr.GetValue(0) End While as of ur 2nd question, i need chk out n will post here later, becoz i forgot the code ...all i can say is updation of DB from DataTable is ALWAYS possible. this is not the end, this is how its goin to begin !

                M Offline
                M Offline
                mayhem_rules
                wrote on last edited by
                #7

                Thnx a lot. I will be waiting for your reply regarding 'Database updation from datatable". Right now I am facing a lot of problem using the traditional method of updating each record since the operation involves huge data. Once again thx for your help. Have a nice day. With Best Regards, Mayur

                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