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. Writting to a database

Writting to a database

Scheduled Pinned Locked Moved Database
databasetutorialquestion
11 Posts 5 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.
  • T Offline
    T Offline
    Tichaona J
    wrote on last edited by
    #1

    I have my database called patients.mdb and I am using the below code to read from it (part of the code): OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close(); How to you write to a database of this type?

    L S D P 4 Replies Last reply
    0
    • T Tichaona J

      I have my database called patients.mdb and I am using the below code to read from it (part of the code): OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close(); How to you write to a database of this type?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      So you discovered one method (ExecuteReader) of the OdbcCommand class, and now you want someone to spoon feed you on another of its methods? too lazy to read a single page on MSDN? Google broke down? What gives? X|

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      T 1 Reply Last reply
      0
      • T Tichaona J

        I have my database called patients.mdb and I am using the below code to read from it (part of the code): OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close(); How to you write to a database of this type?

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Have to agree with Luc on that one, BUT look into the different type of execute from the command object. depending on your database type and how you want to execute the query i.e. SQL or stored procedures you need to read up on ExecuteNonQuery[^]

        As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

        P 1 Reply Last reply
        0
        • L Luc Pattyn

          So you discovered one method (ExecuteReader) of the OdbcCommand class, and now you want someone to spoon feed you on another of its methods? too lazy to read a single page on MSDN? Google broke down? What gives? X|

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          T Offline
          T Offline
          Tichaona J
          wrote on last edited by
          #4

          Thanks for the answer, however just because something seems simple to you doesn't mean it will be to the next arrogent SB.

          L 1 Reply Last reply
          0
          • T Tichaona J

            Thanks for the answer, however just because something seems simple to you doesn't mean it will be to the next arrogent SB.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            if you want to achieve anything at all at programming, you need to learn and help yourself first of all; only when that fails, ask a specific question here and people will be glad to help out. Laziness is not appreciated around here, so start using Google, look at MSDN, buy and study a book, and read some of those nice articles on CodeProject. It is all there to provide basic information and much more. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            1 Reply Last reply
            0
            • T Tichaona J

              I have my database called patients.mdb and I am using the below code to read from it (part of the code): OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close(); How to you write to a database of this type?

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

              What Simon said. Also look at INSERT and UPDATE in SQL, both of which use ExecuteNonQuery.

              CQ de W5ALT

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

              1 Reply Last reply
              0
              • T Tichaona J

                I have my database called patients.mdb and I am using the below code to read from it (part of the code): OdbcDataReader reader = command.ExecuteReader(); while (reader.Read()) { rTxtBxMC.Text = Convert.ToString( reader[0]); } reader.Close(); How to you write to a database of this type?

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

                DatabaseAccessor[^]

                Tichaona J wrote:

                Convert.ToString(

                I suspect that that is completely needless in this case, if the value in the database is already a string then a simple cast is all you need. Don't use the Convert class!

                1 Reply Last reply
                0
                • S Simon_Whale

                  Have to agree with Luc on that one, BUT look into the different type of execute from the command object. depending on your database type and how you want to execute the query i.e. SQL or stored procedures you need to read up on ExecuteNonQuery[^]

                  As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

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

                  ExecuteReader can execute any SQL statement (and more than one at time in some cases); ExecuteNonQuery and ExecuteScalar call it in the background.

                  S 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    ExecuteReader can execute any SQL statement (and more than one at time in some cases); ExecuteNonQuery and ExecuteScalar call it in the background.

                    S Offline
                    S Offline
                    Simon_Whale
                    wrote on last edited by
                    #9

                    I always thought ExecuteReader (one or more rows) and ExecuteScalar (single value) return values from the database, where as ExecuteNonQuery only returns the number of rows returned, i.e a write which the Op was asking about Is the ExecuteReader executing a an insert / update or delete statement something it can do but not by intentional design?

                    As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

                    P 1 Reply Last reply
                    0
                    • S Simon_Whale

                      I always thought ExecuteReader (one or more rows) and ExecuteScalar (single value) return values from the database, where as ExecuteNonQuery only returns the number of rows returned, i.e a write which the Op was asking about Is the ExecuteReader executing a an insert / update or delete statement something it can do but not by intentional design?

                      As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

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

                      Read up more on DataReaders -- they can do anything. The others simply wrap it.

                      S 1 Reply Last reply
                      0
                      • P PIEBALDconsult

                        Read up more on DataReaders -- they can do anything. The others simply wrap it.

                        S Offline
                        S Offline
                        Simon_Whale
                        wrote on last edited by
                        #11

                        Cheers will do

                        As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

                        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