Why DataSet always returns null?
-
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;
}
-
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;
}
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
-
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;
}
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
-
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;
}
"A little knowledge is a dangerous thing." -- Alexander Pope
-
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
-
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;
}
-
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)
You could edit your post. Just make it clear(er) that you have already pointed out the error and are not asking for help.
-
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)
I think a coding horror and a common mistake when misunderstanding the functionality of the language are often confused. Not reading the documentation is an entirely different problem! If this developer had been coding for years, and only just come across try..catch..finally, then I would truly cry, but if this is a newbie, this is a case of being too harsh on your underlings (like the post the other day)
-
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;
}
He should have learned try-catch-finally, not just try-catch.
-
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
-
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;
}
: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
-
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
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
-
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
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
-
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)
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
-
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;
}
-
You are as funny as the programmer. Did you think I am looking for help from you? Read my post again carefully please!
hmmmm .... this how he read the post ... try { CheckIfPostIsInCorrectForum(); } catch { WriteWrongPostMessage(); } finaly { WriteWrongPostMessageExt(); } :) :) :) :) ;P *hehe*
-
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;
}
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?
-
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;
}
:doh:
How many bytes of text have I typed in my lifetime??? Man, I wish I kept track...
-
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;
}
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;
}