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. Other Discussions
  3. The Weird and The Wonderful
  4. Why DataSet always returns null?

Why DataSet always returns null?

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpquestion
23 Posts 17 Posters 5 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.
  • C che3358

    A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

    private DataSet GetData()
    {
    DataSet ds = null;
    try
    {
    ds = new DataSet();
    //Get data
    //And assign ds = someData
    }
    catch
    {
    //Handle some error
    }
    finally
    {
    ds = null;
    }

     return ds;
    

    }

    B Offline
    B Offline
    blackjack2150
    wrote on last edited by
    #9

    He should have learned try-catch-finally, not just try-catch.

    1 Reply Last reply
    0
    • D Dan Neely

      That said, I suggest you and your cow-orker might want to start by learning what the finally block does.

      Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

      B Offline
      B Offline
      Baixinho
      wrote on last edited by
      #10

      I think this post is really on thr right forum :) It gave me a laught :)

      Sérgio Lima Many people would sooner die than think; In fact, they do so. - Bertrand Russell

      1 Reply Last reply
      0
      • C che3358

        A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

        private DataSet GetData()
        {
        DataSet ds = null;
        try
        {
        ds = new DataSet();
        //Get data
        //And assign ds = someData
        }
        catch
        {
        //Handle some error
        }
        finally
        {
        ds = null;
        }

         return ds;
        

        }

        M Offline
        M Offline
        MarkB777
        wrote on last edited by
        #11

        :doh:

        che3358 wrote:

        A programmer student told me he just learned was just starting to learn try...catch

        Mark Brock Click here to view my blog

        1 Reply Last reply
        0
        • D Dan Neely

          That said, I suggest you and your cow-orker might want to start by learning what the finally block does.

          Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #12

          Ummm, it is in the correct forum. The posted code is somewhat a horror.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          1 Reply Last reply
          0
          • R Robert Royall

            Your programmer didn't learn try...catch as well as he thought he did.

            Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world. -Me explaining my job to an engineer

            modified on Thursday, June 26, 2008 11:26 AM

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #13

            Robert Royall wrote:

            Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope. Welcome to my world.

            Very true. I like that.

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            1 Reply Last reply
            0
            • C che3358

              Since some experienced programmers like Dan Neely didn't get humor feeling from my post, I do need to add the following words at the bottom of my post: (Hint: the programmer set ds = null in section finally before returning his ds)

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #14

              che3358 wrote:

              (Hint: the programmer set ds = null in section finally before returning his ds)

              That was one of the first things I noticed :-\

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              1 Reply Last reply
              0
              • C che3358

                A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

                private DataSet GetData()
                {
                DataSet ds = null;
                try
                {
                ds = new DataSet();
                //Get data
                //And assign ds = someData
                }
                catch
                {
                //Handle some error
                }
                finally
                {
                ds = null;
                }

                 return ds;
                

                }

                K Offline
                K Offline
                kiennt
                wrote on last edited by
                #15

                cause: finally { ds = null; }

                A 1 Reply Last reply
                0
                • C che3358

                  You are as funny as the programmer. Did you think I am looking for help from you? Read my post again carefully please!

                  G Offline
                  G Offline
                  GFJ_Freespirit77
                  wrote on last edited by
                  #16

                  hmmmm .... this how he read the post ... try { CheckIfPostIsInCorrectForum(); } catch { WriteWrongPostMessage(); } finaly { WriteWrongPostMessageExt(); } :) :) :) :) ;P *hehe*

                  1 Reply Last reply
                  0
                  • K kiennt

                    cause: finally { ds = null; }

                    A Offline
                    A Offline
                    Anthony Mushrow
                    wrote on last edited by
                    #17

                    I think we knew that already ;)

                    My current favourite word is: I'm starting to run out of fav. words!

                    -SK Genius

                    Game Programming articles start -here[^]-

                    1 Reply Last reply
                    0
                    • C che3358

                      A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

                      private DataSet GetData()
                      {
                      DataSet ds = null;
                      try
                      {
                      ds = new DataSet();
                      //Get data
                      //And assign ds = someData
                      }
                      catch
                      {
                      //Handle some error
                      }
                      finally
                      {
                      ds = null;
                      }

                       return ds;
                      

                      }

                      R Offline
                      R Offline
                      Ri Qen Sin
                      wrote on last edited by
                      #18

                      A simple programming oversight. :laugh:

                      So the creationist says: Everything must have a designer. God designed everything. I say: Why is God the only exception? Why not make the "designs" (like man) exceptions and make God a creation of man?

                      1 Reply Last reply
                      0
                      • C che3358

                        A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

                        private DataSet GetData()
                        {
                        DataSet ds = null;
                        try
                        {
                        ds = new DataSet();
                        //Get data
                        //And assign ds = someData
                        }
                        catch
                        {
                        //Handle some error
                        }
                        finally
                        {
                        ds = null;
                        }

                         return ds;
                        

                        }

                        K Offline
                        K Offline
                        Kenny McKee
                        wrote on last edited by
                        #19

                        :doh:

                        How many bytes of text have I typed in my lifetime??? Man, I wish I kept track...

                        1 Reply Last reply
                        0
                        • C che3358

                          A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:

                          private DataSet GetData()
                          {
                          DataSet ds = null;
                          try
                          {
                          ds = new DataSet();
                          //Get data
                          //And assign ds = someData
                          }
                          catch
                          {
                          //Handle some error
                          }
                          finally
                          {
                          ds = null;
                          }

                           return ds;
                          

                          }

                          C Offline
                          C Offline
                          che3358
                          wrote on last edited by
                          #20

                          His purpose was to clear object DataSet in section finally. But, do you guys think the DataSet will be cleared if no error is caught?

                          private bool CheckData()
                          {
                          DataSet ds = null;
                          try
                          {
                          //Get Data, and fill ds
                          //if there is data in the ds's table
                          return true;
                          }
                          catch{}
                          finally
                          {
                          ds = null;
                          }

                          return false;
                          

                          }

                          L 1 Reply Last reply
                          0
                          • C che3358

                            His purpose was to clear object DataSet in section finally. But, do you guys think the DataSet will be cleared if no error is caught?

                            private bool CheckData()
                            {
                            DataSet ds = null;
                            try
                            {
                            //Get Data, and fill ds
                            //if there is data in the ds's table
                            return true;
                            }
                            catch{}
                            finally
                            {
                            ds = null;
                            }

                            return false;
                            

                            }

                            L Offline
                            L Offline
                            Lieutenant Frost
                            wrote on last edited by
                            #21

                            Uhh...yes? That's the entire point of the Finally... statement. :doh:

                            “Acer, Gateway, and eMachines are the same company now. Great! Now we just need a really big toilet, and we can get rid of all three at once.”

                            1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              "A little knowledge is a dangerous thing." -- Alexander Pope

                              C Offline
                              C Offline
                              Chris Quinn
                              wrote on last edited by
                              #22

                              Just to be pedantic - Pope's quotation is actually "A little learning is a dangerous thing"

                              ==================================== Transvestites - Roberts in Disguise! ====================================

                              1 Reply Last reply
                              0
                              • D Dan Neely

                                That said, I suggest you and your cow-orker might want to start by learning what the finally block does.

                                Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                                B Offline
                                B Offline
                                BillW33
                                wrote on last edited by
                                #23

                                This post is definitely in the correct forum. The poster knows what is wrong with the code. The person that is new to try/catch/finally doesn’t realize it yet ;)

                                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