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. Database & SysAdmin
  3. Database
  4. read & update using reader

read & update using reader

Scheduled Pinned Locked Moved Database
databasequestionsharepointtutorialannouncement
34 Posts 15 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.
  • J Jassim Rahma

    I have the following to read from database: sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString); sql_connection.Open(); sql_command = new MySqlCommand("sp_send_pending_sms", sql_connection); sql_command.CommandType = CommandType.StoredProcedure; sql_reader = sql_command.ExecuteReader(); after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide.. Thanks

    R Offline
    R Offline
    RaviRanjanKr
    wrote on last edited by
    #2

    jrahma wrote:

    after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide..

    A little bit confusing about your question whatever, In case of save,update and delete you need to execute Transact SQL statement against connection. :)

    modified on Sunday, December 12, 2010 10:17 AM

    N S 2 Replies Last reply
    0
    • J Jassim Rahma

      I have the following to read from database: sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString); sql_connection.Open(); sql_command = new MySqlCommand("sp_send_pending_sms", sql_connection); sql_command.CommandType = CommandType.StoredProcedure; sql_reader = sql_command.ExecuteReader(); after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide.. Thanks

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #3

      You have been around here long enough to know to format code snippets properly. Edit your post to correct this. How do you expect the database to know what operations have occurred after retrieving the data? You have to tell it, with a SQL statement of some type.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • R RaviRanjanKr

        jrahma wrote:

        after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide..

        A little bit confusing about your question whatever, In case of save,update and delete you need to execute Transact SQL statement against connection. :)

        modified on Sunday, December 12, 2010 10:17 AM

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #4

        RaviRanjankr wrote:

        need to execute Transact SQL statement against connection

        :rolleyes: Well, DAH!! Of course you do, but how does this answer the question?


        I know the language. I've read a book. - _Madmatt

        R 1 Reply Last reply
        0
        • N Not Active

          RaviRanjankr wrote:

          need to execute Transact SQL statement against connection

          :rolleyes: Well, DAH!! Of course you do, but how does this answer the question?


          I know the language. I've read a book. - _Madmatt

          R Offline
          R Offline
          RaviRanjanKr
          wrote on last edited by
          #5

          Mark Nischalke wrote:

          how does this answer the question?

          :doh: Ok its my fault but can you explain what extra I have to mention here.

          N M 2 Replies Last reply
          0
          • J Jassim Rahma

            I have the following to read from database: sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString); sql_connection.Open(); sql_command = new MySqlCommand("sp_send_pending_sms", sql_connection); sql_command.CommandType = CommandType.StoredProcedure; sql_reader = sql_command.ExecuteReader(); after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide.. Thanks

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #6

            If you use stored procedures (and you shouldn't), don't prefix the names with "sp"[^]. When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent. "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1" Send the emails. "UPDATE Email SET Status=2 WHERE Status=1"

            M J G J 4 Replies Last reply
            0
            • R RaviRanjanKr

              Mark Nischalke wrote:

              how does this answer the question?

              :doh: Ok its my fault but can you explain what extra I have to mention here.

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #7

              RaviRanjankr wrote:

              what extra I have to mention here

              :wtf: You provide enough to answer the question that was asked. :rolleyes: Take some time to read other responses around the forums and learn.


              I know the language. I've read a book. - _Madmatt

              R 1 Reply Last reply
              0
              • P PIEBALDconsult

                If you use stored procedures (and you shouldn't), don't prefix the names with "sp"[^]. When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent. "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1" Send the emails. "UPDATE Email SET Status=2 WHERE Status=1"

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #8

                PIEBALDconsult wrote:

                If you use stored procedures (and you shouldn't),

                Do you want to clarify that statement.

                Never underestimate the power of human stupidity RAH

                P M 2 Replies Last reply
                0
                • M Mycroft Holmes

                  PIEBALDconsult wrote:

                  If you use stored procedures (and you shouldn't),

                  Do you want to clarify that statement.

                  Never underestimate the power of human stupidity RAH

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #9

                  Nah, not so soon after the last time. I'll just opine that that particular poster probably shouldn't. :-D

                  1 Reply Last reply
                  0
                  • N Not Active

                    RaviRanjankr wrote:

                    what extra I have to mention here

                    :wtf: You provide enough to answer the question that was asked. :rolleyes: Take some time to read other responses around the forums and learn.


                    I know the language. I've read a book. - _Madmatt

                    R Offline
                    R Offline
                    RaviRanjanKr
                    wrote on last edited by
                    #10

                    Thanks for your support and nice idea. :-D

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      If you use stored procedures (and you shouldn't), don't prefix the names with "sp"[^]. When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent. "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1" Send the emails. "UPDATE Email SET Status=2 WHERE Status=1"

                      J Offline
                      J Offline
                      Jassim Rahma
                      wrote on last edited by
                      #11

                      When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent.

                      "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1"

                      Send the emails.

                      "UPDATE Email SET Status=2 WHERE Status=1"

                      yup but my question, is I am reading the pending SMSs using sql_reader1 then how can I execute the update status code? can I do it using the same sql_reader? it won't allow braces the sql reader is still open! should I have sql_reader1 for reading the pending sms and within the while (sql_reader1.Read()) I will have sql_reader2? please advise..

                      P M P 3 Replies Last reply
                      0
                      • J Jassim Rahma

                        When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent.

                        "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1"

                        Send the emails.

                        "UPDATE Email SET Status=2 WHERE Status=1"

                        yup but my question, is I am reading the pending SMSs using sql_reader1 then how can I execute the update status code? can I do it using the same sql_reader? it won't allow braces the sql reader is still open! should I have sql_reader1 for reading the pending sms and within the while (sql_reader1.Read()) I will have sql_reader2? please advise..

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        You can do it that way (you have a unique ID, yes?), but you'll need a second Connection as well. There are times you need to do that.

                        1 Reply Last reply
                        0
                        • R RaviRanjanKr

                          jrahma wrote:

                          after reading I want to update every record when send to set the field is_sent to True? how can i do this? do I have to create another reader in the middle? can you please guide..

                          A little bit confusing about your question whatever, In case of save,update and delete you need to execute Transact SQL statement against connection. :)

                          modified on Sunday, December 12, 2010 10:17 AM

                          S Offline
                          S Offline
                          ShilpaKumari
                          wrote on last edited by
                          #13

                          Good sot, You need to elobrate it how they achieve

                          1 Reply Last reply
                          0
                          • J Jassim Rahma

                            When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent.

                            "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1"

                            Send the emails.

                            "UPDATE Email SET Status=2 WHERE Status=1"

                            yup but my question, is I am reading the pending SMSs using sql_reader1 then how can I execute the update status code? can I do it using the same sql_reader? it won't allow braces the sql reader is still open! should I have sql_reader1 for reading the pending sms and within the while (sql_reader1.Read()) I will have sql_reader2? please advise..

                            M Offline
                            M Offline
                            Mycroft Holmes
                            wrote on last edited by
                            #14

                            jrahma wrote:

                            using sql_reader1

                            I have never understood the reason so many devs use the reader, sure it is he most economic way to process data but the limitations are irritating. I ALWAYS get the data, all the data into a datatable/List<>, this frees up the connection, then I process the datatable. If the data set is too large then I get the data to process in chunks.

                            Never underestimate the power of human stupidity RAH

                            P 1 Reply Last reply
                            0
                            • J Jassim Rahma

                              When I implement a system like that, sending email or whatever, I put a Status field in the table to indicate ( 0=New , 1=Sending , 2=Sent ). When I select the New rows, I also set the Status to Sending, then when I'm done I set the Sending rows to Sent.

                              "UPDATE Email SET Status=1 WHERE Status=0 ; SELECT * FROM Email WHERE Status=1"

                              Send the emails.

                              "UPDATE Email SET Status=2 WHERE Status=1"

                              yup but my question, is I am reading the pending SMSs using sql_reader1 then how can I execute the update status code? can I do it using the same sql_reader? it won't allow braces the sql reader is still open! should I have sql_reader1 for reading the pending sms and within the while (sql_reader1.Read()) I will have sql_reader2? please advise..

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #15

                              If you are trying to update a value and you are already using the connection for reading data, you need to look at using a MARS connection (that's Multiple Active Result Set). Add MultipleActiveResultSets=true; to your connection string.

                              I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                              Forgive your enemies - it messes with their heads

                              My blog | My articles | MoXAML PowerToys | Onyx

                              P 1 Reply Last reply
                              0
                              • P Pete OHanlon

                                If you are trying to update a value and you are already using the connection for reading data, you need to look at using a MARS connection (that's Multiple Active Result Set). Add MultipleActiveResultSets=true; to your connection string.

                                I'm not a stalker, I just know things. Oh by the way, you're out of milk.

                                Forgive your enemies - it messes with their heads

                                My blog | My articles | MoXAML PowerToys | Onyx

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #16

                                With MySQL?

                                1 Reply Last reply
                                0
                                • M Mycroft Holmes

                                  jrahma wrote:

                                  using sql_reader1

                                  I have never understood the reason so many devs use the reader, sure it is he most economic way to process data but the limitations are irritating. I ALWAYS get the data, all the data into a datatable/List<>, this frees up the connection, then I process the datatable. If the data set is too large then I get the data to process in chunks.

                                  Never underestimate the power of human stupidity RAH

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #17

                                  I have never understood the reason so many devs use the DataAdapter and load a whole butt-load of data at once when they don't use it all at once. Certainly, when I want to load a ListBox or something, I use a DataTable (loaded straight from a DataReader), but mostly I use only one record at a time -- to export or copy somewhere or update something. For what I do, I doubt the connection stays open significantly longer, but it sure saves on RAM and class instantiations. Bear in mind that I generally write Windows Services that cycle every ten to fifteen seconds, and not generally GUI apps that spend a lot of time just sitting there displaying a bunch of out-dated data. And when I do write a WinForms app that displays a butt-load of data, I often use a Service to create an (XML) export that the clients read, rather than have all the clients constantly clambering for database connections.

                                  M F 2 Replies Last reply
                                  0
                                  • P PIEBALDconsult

                                    I have never understood the reason so many devs use the DataAdapter and load a whole butt-load of data at once when they don't use it all at once. Certainly, when I want to load a ListBox or something, I use a DataTable (loaded straight from a DataReader), but mostly I use only one record at a time -- to export or copy somewhere or update something. For what I do, I doubt the connection stays open significantly longer, but it sure saves on RAM and class instantiations. Bear in mind that I generally write Windows Services that cycle every ten to fifteen seconds, and not generally GUI apps that spend a lot of time just sitting there displaying a bunch of out-dated data. And when I do write a WinForms app that displays a butt-load of data, I often use a Service to create an (XML) export that the clients read, rather than have all the clients constantly clambering for database connections.

                                    M Offline
                                    M Offline
                                    Mycroft Holmes
                                    wrote on last edited by
                                    #18

                                    PIEBALDconsult wrote:

                                    I generally write Windows Services that cycle every ten to fifteen seconds

                                    Well I do write user apps that have the (outdated) data sitting in front of the user, with move to WCF we use observablecollections serviced to the UI. I suppose we could use the reader instead of the adapter, it is just a habit from the winforms when we used to datatable as the bindingsource to the grids.

                                    Never underestimate the power of human stupidity RAH

                                    P 1 Reply Last reply
                                    0
                                    • M Mycroft Holmes

                                      PIEBALDconsult wrote:

                                      I generally write Windows Services that cycle every ten to fifteen seconds

                                      Well I do write user apps that have the (outdated) data sitting in front of the user, with move to WCF we use observablecollections serviced to the UI. I suppose we could use the reader instead of the adapter, it is just a habit from the winforms when we used to datatable as the bindingsource to the grids.

                                      Never underestimate the power of human stupidity RAH

                                      P Offline
                                      P Offline
                                      PIEBALDconsult
                                      wrote on last edited by
                                      #19

                                      Mycroft Holmes wrote:

                                      grids

                                      X| Wash your mouth out with tequila; you're better than that.

                                      M 1 Reply Last reply
                                      0
                                      • P PIEBALDconsult

                                        Mycroft Holmes wrote:

                                        grids

                                        X| Wash your mouth out with tequila; you're better than that.

                                        M Offline
                                        M Offline
                                        Mycroft Holmes
                                        wrote on last edited by
                                        #20

                                        In this context a grid is a generic term for a collection control and with winforms I was always happy to bind a datatable to a datagirdview, the datatable is disconnected afterall. The cost of the datatable has always been irrelevant to the functionality that it brings. Then we were told to use services and I decided the UI should be silverlight so everything changed, now it's Oracle databases, WCF, observablecollections, viewmodels and xaml. Did I say I hate (relearning) Oracle.

                                        Never underestimate the power of human stupidity RAH

                                        P 1 Reply Last reply
                                        0
                                        • M Mycroft Holmes

                                          In this context a grid is a generic term for a collection control and with winforms I was always happy to bind a datatable to a datagirdview, the datatable is disconnected afterall. The cost of the datatable has always been irrelevant to the functionality that it brings. Then we were told to use services and I decided the UI should be silverlight so everything changed, now it's Oracle databases, WCF, observablecollections, viewmodels and xaml. Did I say I hate (relearning) Oracle.

                                          Never underestimate the power of human stupidity RAH

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #21

                                          Mycroft Holmes wrote:

                                          (relearning) Oracle.

                                          But not in C with Pro*C I bet.

                                          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