OK, Databases are nasty but I can usually puzzle my way through and here's how I interpret your trouble with instantiation.
Code:
DataSet ds = new DataSet();
This is actually two expressions condensed into one. I'm so used to it I can't remember the separated format but basically
Is declaring a variable, it's saying that ds is a new variable of type DataSet. At THIS point there IS no DataSet, simply a variable waiting to have a REAL DataSet put into it. The second part...
Code:
ds = new DataSet();
uses the NEW keyword to create a REAL DataSet. ds = then assigns the new DataSet to ds. NOW ds has a DataSet sitting inside it that you can program against. It sounds like you're at least partly OK with this.
Here's the part you said you're confused about. A DataSet has it's own internal structure, in fact it's set up very much like a Database. You've recognized that DataSets have a table(s) inside them, in fact for a moment in the code you even get to "see" them.
Code:
da.Fill(ds, "Random001");
return ds.Tables["Random001"];
It looks like they're sitting there for you to use, right? I admit I don't get how ASP.NET lets you make that call when it obviously won't let you use it the way you want to. (There must be some data type conversioning going on from the ds.Table to a full DataTable type, at least that's my best guess)
The upshot is that the table has to be declared explicitly. The giveaway is the error message you get. When you try to access the table using ds.Table it tells you "Hey, I can't find anything." Once you explicitly declare the DataTable...
Code:
DataTable dt = GetRandLinks();
it's smooth sailing. Obviously the part which directly addresses your error is
Code:
dt = GetRandLinks();
That's the part which fills your DataTable variable with the actual table. Hope that part helps anyway.
:)
-------------------------
Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe
When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper
Chroniclemaster1, Founder of
www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.