Some doubts about ado.net

  • Thread starter Thread starter Alcibiade
  • Start date Start date
A

Alcibiade

Hello, I have a general question about db, dataset and so on
Is it right to create a db without relations but creating these in the
dataset?
When i create the application, visual studio load all data inside datatables
but people say it is wrong: you should load only data you need, use them and
then release the memory......
So,i f I have a list of users in a table, is it correct loading all in the
dataset only their data and when the user is selected, load all data about
the choosen item?

In this case what the advantage about using ado.net with binding, datatabel
and so on instead to make querys on fly on db?
I read : by ado.net u can load all data in memory so that you can limit db
accesses tahey are slow a lot and it allows to limit traffic of data on the
net....

Sorry for the long post, but I 'd like to know more about this but by now I
have only many doubts in my mind
Thanks
 
Hello, I have a general question about db, dataset and so on
Is it right to create a db without relations but creating these in the
dataset?

Let me ask a question, using a bit of an analogy: If you were a king in
medieval times, would you send out your army while living in a shack or
would you build a castle first?

In business, data is king. if your king is dead, your business is dead.

Data = king
Castle = database
Army = developers

If you send out the army and they are flanked, but there is no castle =
dead king. That is the the answer to the question you are asking.

Taking the analogy full circle, you should make sure no bad data can
enter the database on the database side. If you want to save cycles, you
can repeat the exercise in your dataset, but leaving a database without
relationships and constraints leaves the ability of bad data entering
the system, no matter how good the developers are.
When i create the application, visual studio load all data inside
datatables but people say it is wrong: you should load only data you
need, use them and then release the memory......

Of the options, i would only load the data I need today and avoid asking
someone to save me many months, or years, later.

Today, you might say. But it is easier to select * from table. Tomorrow,
when you have one million rows and the application takes five minutes to
load a page, you will be asking us how to speed it up.
So,i f I have a list of users in a table, is it correct loading all in
the dataset only their data and when the user is selected, load all
data about the choosen item?

if they are not going to edit other people's data, then I would only
load their data.
In this case what the advantage about using ado.net with binding,
datatabel and so on instead to make querys on fly on db?

It depends on whether you are actually binding or not. I fyou are
binding to a page, you need some type of object model.

Or, it can depend on whether or not you are using the drag and drop
bits. For example, when you create a data table, you also get a table
adapter. The table adapter makes it easy to attach queries.

So, if you are actually binding to UI bits, or you are using the drag
and drop "goodness", there is a strong advantage to using ADO.NET
DataSets.

Can you write everything yourself? Sure. In fact, if you have enough
time and initiative, you can write the code for a completely new type of
operating system. It just depends on where you want to spend your time.
Using ADO.NET with either DataSets, Entity Framework or LINQ to SQL
speeds up time to market. That is their main advantage.
I read : by ado.net u can load all data in memory so that you can
limit db accesses tahey are slow a lot and it allows to limit traffic
of data on the net....

It is called caching.

Peace and Grace,



--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Alcibiade said:
Hello, I have a general question about db, dataset and so on
Is it right to create a db without relations but creating these in the
dataset?

There isn't a simple answer to that question. Databases are often used by
many different kinds of applications, but those different applications may
have common data needs. You may need to create relationships in the
database itself to aid in the execution of stored procedures and to be able
to enforce referential activity (you wouldn't normally want someone to be
able to delete a customer if there are related unfufilled orders for that
customer). So, creating the relationships in the database is very often
needed.

Being able to create relationships "on the fly" for disconnected data that
you've downloaded into a DataSet is a very powerful thing to be able to do
and you'd generally do that when you have an application-specfic reason for
needing those relationships.

I don't think you should think of this as an "either or" question. It's
more like which one best fits, not only the needs of one particular
application, but will that same solution be needed for many applications.
When i create the application, visual studio load all data inside
datatables but people say it is wrong: you should load only data you need,
use them and then release the memory......
So,i f I have a list of users in a table, is it correct loading all in the
dataset only their data and when the user is selected, load all data about
the choosen item?

Again, there is no one answer here, it really depends on the data. It is
true that you probably don't need to download 50,000 records into your
disconnected DataSet, when you want to be able to have an application that
let's the end user browse records. Instead you'd design your intial query
to get a smaller, eaiser to manage amount and then when the user has
exhausted those, you can go back to the database and get another chunk.

If, on the other hand, there isn't much data to get in the first place, then
sure, go ahead and get it all to avoid having to make another trip to the
database.
In this case what the advantage about using ado.net with binding,
datatabel and so on instead to make querys on fly on db?

Well, that's a very broad question that doesn't really make much sense. ADO
..NET is simply the name for types in the .NET Framework that allow you to
work with data (both connected and disconnected). You can certainly make a
query and execute it "on the fly" with ADO .NET, by working with a
Connection, a Command, and a DataReader. But, you may want to store the
data you just got from your query so a DataTable or DataSet might be
helpful.

I think what you are missing is that ADO .NET has types for working with
your data store in a "connected" way and a "disconnected" way.

As for data-binding, that really isn't relevant to how you are going about
getting your hands on the data. It only has to do with what you want to do
with the data once you've gotten it.
I read : by ado.net u can load all data in memory so that you can limit db
accesses tahey are slow a lot and it allows to limit traffic of data on
the net....

Most of that statement is true. But to say that it is slow is not really
accurate, as a general statement. Again, it depends on what you are
attempting to get. If you go to the database once and get 100,000 records,
you will save many trips to the database, but you'll wait a while for all
the data to be returned to your application. If you go to the database 10
times and get 10,000 records each time, each call will be faster, but you'll
make more database calls. The trick is to find the right balance between
how much data your appliciation needs at one time and how many times you
need to access your database for that data.

-Scott
 
Back
Top