Dataset and Datatable - Differences ??
I know this is going to sound naive but I am having a lot of trouble getting my head around ado.net.
Is this right ?
A dataset is a collection of tables and relationships
A table is a collection of rows and columns
===================================
Why is it that in some examples I find people bind controls to datasets AND sometimes tables ?
What are the advantages using each approach ?
===================================
If I fill a table using a dataadaptor (no dataset) and add a row can I reflect those changes back into the database ?
Thanks
Re: Dataset and Datatable - Differences ??
For a recent (ASP.NET) project I created my own basic ORM layer. It had singleton mapper classes for each table that exposed methods to find, save, and delete objects. Then the Business Layer has the objects (and collections of those objects) that hold the data. The business objects also exposed properties for collections. Say for instance you have an Employee object. It would contain properties that would reference the boss Employee object, and the subordinate employees collection.
You would use it like this:
Employee joe = EmployeeMapper.Instance.Find(23); //23 is joe's employee ID
if (joe != null)
{
dlstPeopleUnderJoe.DataSource = joe.Subordinates;
dlstPeopleUnderJoe.DataBind();
joe.Sallary = 35000;
EmployeeMapper.Instance.Save(joe);
}
All the collections were lazy loaded, and (in this case) the boss would be lazy loaded because otherwise the loading would recurse all the way to the CEO. Anyways, each mapper class had caches, so for instance, the EmployeeMapper would have a cache (Dictionary of sorts) that would relate each Employee object to it's EmployeeID value. That way when someone else requests the data for Employee with ID X, the mapper checks the cache before going to the DB. Collections were also cached, so if two people requested the list of employees under employee X, the collection is only loaded from the DB once. All the cached data is held by WeakReferences in the mappers, so if no one is holding a reference to the data, and .NET needs memory the cached data is simply removed by .NET.
The collections can be sorted using custom IComparer objects, but they can't be filtered. I'm still trying to think of a way to build this around Datasets, DataTables, Views, etc. If it could use a typed dataset behind the scenes, you could still have the clarity of joe.CurrentProjects[0].Department.HeadManager.FullName and be able to filter/sort collections.
What do you guys think? Am I crazy? :)
Re: Dataset and Datatable - Differences ??
I worked on project recently and we had an ILookup for some of the tables, but only the ones that were very redundant. Like they all had an ID, a name and a description. These were all cached in a global(session) cache. None of the more complex data classes were cached and I often wondered why we didn't have a Singleton because every thing out of the cache was cloned when it came out... but we had a pretty hefty concurancy model in place.
The concurancy modal hit the DB and compared version x with version fresh to see if it was the same. If two+ fields where not the same a concurency error was thrown in the BLL I think....
What really boggled my mind was that they weren't lazyloading to start with they only lazy loaded if things seemed slow... I didn't like a lot of things about the object modal but it worked... it had four layers DAL, DLL, BLL, and the IVL( Interface Validation) DAL, and DLL were redundant and DLL was in the BLL project... I found myself having to write special case data classes for reports because the classes they had were so f'n slow... no custom collections all ArrayList... anytime I did a find I had to cast to the class because they had an abstract base class and they wouldn't let me change it so that you could hide it's FindOne with new and have it come out the correct class type....
I got really fed up one day and documented an object modal I had been planing for my next project before I started there and they were like that won't work.... and then about a month later they were like oh that would work 50 times better than this... part of what I explained was that the DA/LL should be the bottom layer and should implement the structure of the table that way the BLL can simply inherit from it... and that the DA/LL should be one layer...
It was thier first .net project though and I know I didn't do great on my first .net project... what really got to me though was that I always had to argue for 4 hrs to get permission to make an improvement and explain and re explain why I wanted to do it. Man, one guy refused to use my code, because, well I don't really know why... I had created a base report class that extended the report class and would auto format the report, check the printer capabilities and ensure security rights to the printer. In truth I had made it to fix a lot of problem that were coming up with printing the reports and it did that. Later there were things all reports had to have that were put here but this guy just refused to use the class. The joke was that I was the better programmer and he couldn't take it... I was always having to fix his code...not for him but it get would put on my plate and it wouldn't be working... so... we got along in terms of going out back to bs and smoke a cig but... he would not use my code lol
anyway I think I got off on a tangent here. I don't think your crazy lol
Re: Dataset and Datatable - Differences ??
I had one experience where the UI would show the user a list of databases and in each database would be a table of runs or trials. For some reason the customer wanted to be able to create new databases at run-time, presumably so they could easily transfer a group of 'runs' between computers. The original UI design had a drop down for the databases and then a New button next to it for a new DB. I was in charge of creating the GUI and I told them they should take the new button out and stick an option at the bottom of the DB list like <<New Database>> and it took them a while to bite. After working on it a while I thought it would be easier on me to have a seperate button because I wanted to databind the DB list. So the same people fight back and tell me that if theres a list and a button then the user will not know whether to select a DB or create a new one. I didn't know how to respond to that!