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. returning a datareader

returning a datareader

Scheduled Pinned Locked Moved C#
questiondatabase
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.
  • _ Offline
    _ Offline
    _Searcher_
    wrote on last edited by
    #1

    Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?

    C A 2 Replies Last reply
    0
    • _ _Searcher_

      Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?

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

      _Searcher_ wrote: My question is if I can return a data in the same way you return a string or int? Yes _Searcher_ wrote: And how do i do this? For example:

      public DataReader MyMethod()
      {
      DataReader dr = myCommand.ExecuteDataReader();
      return dr;
      }

      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 The Second EuroCPian Event will be in Brussels on the 4th of September

      1 Reply Last reply
      0
      • _ _Searcher_

        Hello! I want to create a method that connects to a sql db and retrives some values. I want the connection in a method so I can reuse the code. My question is if I can return a data in the same way you return a string or int? And how do i do this?

        A Offline
        A Offline
        Aryadip
        wrote on last edited by
        #3

        Well the earlier response I guess answers your question. I just would like to add that you may go through Microsoft Data Application Block(downloadable from Microsoft site) and use their ready made methods to connect to database and retrieve or insert data. It is damn simple to use and very very efficient... believe me... and lines of code???... Imagine writing just 2 lines of code to retrieve data from database... To give you a picture... the application block manages the connection... you only need to supply the query... Cheers... Aryadip. Cheers !! and have a Funky day !!

        _ 1 Reply Last reply
        0
        • A Aryadip

          Well the earlier response I guess answers your question. I just would like to add that you may go through Microsoft Data Application Block(downloadable from Microsoft site) and use their ready made methods to connect to database and retrieve or insert data. It is damn simple to use and very very efficient... believe me... and lines of code???... Imagine writing just 2 lines of code to retrieve data from database... To give you a picture... the application block manages the connection... you only need to supply the query... Cheers... Aryadip. Cheers !! and have a Funky day !!

          _ Offline
          _ Offline
          _Searcher_
          wrote on last edited by
          #4

          Thanks so much for the answers! It worked out great. I didnt try the data application block, but I will look in to that later!

          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