please help on some general concepts on data c# 2.0 vs2005

A

AAJ

Hi all

FIRST THE BORING BITS.......

I normally use a Database layer, a Business layer and a GUI layer.

The GUI uses an Object data source to bind to the Business layer which in
turn binds to the database layer. Every thing is great. I can read data,
change data in the grid, update the database, and when the GUI reloads, all
the changes are all present and correct. i.e. the data seems to be persisted
in the physical databse and re read when the pages are refreshed.

In my current case I want to do some thing similar but am unsure of the
concepts I need to follow.

This time, I have manually created a datatable in a dataset (strongly typed
using XML) which forms my database layer (BUT this does not connect to a
physical database, its just a manually programatically creates and populates
the dataset with data)

My business layer connects to this database layer.

As usual, my GUI connects to the business layer and the data is presented in
a gridview.

All this works fine. Data is displayed, I can click on the edit of the
gridview, this allows me to change the data, write the data to my business
layer, which then updates the dataset held in the databse layer. This all
works.

however......

After the update has been performed the GUI refreshes, and my business and
database layers are destroyed and and then re created as the Object Dataset
re initialises itsself and its data.

AND EVENTUALLY THE QUESTION........

What I can't understand is - How do I persist my dataset without writing it
to a database. I just want to keep a dataset live to which my GUI's can
write to and treat as though they were a true database datatable, throughout
the lifetime of a client being connected.

hope someone can help,

many thanks

Andy

P.s. I know I can use a viewstate etc on my GUI, but I want the database
layer itsself to manage its own perstistance, so please help, there must be
some pattern or tutorial out there.
 
K

Kevin Spencer

Hi AAJ,

First question:
After the update has been performed the GUI refreshes, and my business and
database layers are destroyed and and then re created as the Object
Dataset re initialises itsself and its data.

Why??? This seems like an enormous waste of system resources, destroying and
re-creating your business and database layers with each refresh of the UI.
Are you talking about an ASP.Net app by any chance?
AND EVENTUALLY THE QUESTION........

What I can't understand is - How do I persist my dataset without writing
it to a database.

The answer is not easy to say without more information. Where did you get
the data to populate the DataSet from in the first place? Regardless of
whether it comes from a database or not, it has to come from *somewhere*.
And that would logically be the place to store the changes.

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

I just flew in from Chicago with
a man with a wooden leg named Smith
who shot an elephant in my pajamas.
So I bit him.
 
F

fitim skenderi

Use singleton pattern

You would create one instance of a class then use that instance to bring you
the dataset to any of your GUI forms.


Example would be:

public class MySingleton
{
private static MySingleton mObj;

private Dataset mDataset;

private MySingleton()
{
// intitalise your dataset here
mDataset = new Dataset();
}

public static MySingleton Instance
{
get
{
if(mObj == null) // only one instance is created
mObj = new MySingleton();

return mObj;
}
}

public Dataset MyDataset
{
get { return mDataset; }
}
}


then in your code you would use the singleton like

private void PopulateGui()
{
dataGridView1.Datasource = .MySingleton.Instance.MyDataset;
...
}


hope this helps


Fitim Skenderi
 
A

AAJ

Hi Kevin

You've hit the nail on my head, its not by choice but due to my non
understanding, i.e. when my gui says something like

myBusinessLayer newlayer = new myBusinessLayer ();

then won't everything within 'newlayer' will be destroyed and recreated if
the page refreshes. (including the contents of it). This means that the
class has to be recreated and repopulated from the data base every time the
user changes page. The only way I can keep all the contents of newlayer
alive is by adding it to a viewstate and re copying it back in if !PostBack,
using cookies etc...

The second question you asked, is that the data initially comes from an
Excel spread sheet, and I don't want to use this to perstist the data. What
I want to do is load the data from the sheet, perform initial validation and
put it in a DataTable within a DataSet (I can do this no problem). The data
is then presented to the user in a grid (no problem), It can be updated (no
problem), but as the page updates, because my page has :-

myBusinessLayer newlayer = new myBusinessLayer ();

the businesslayer is destroyed and recreated and so the dataset is
recreated. Again, I know I could use viewstates, serialisation etc, or write
to my sql server, and re load but this seems a wastefull. What I think I'm
trying to do is populate and hold a dataset on the server side, and keep the
data live regardless of clients refreshing etc.

In a non web app, I would be able to just instantiate the object once and
keep it alive as long as I like, but because web pages seem to be stateless,
I can't figure on how to do it.


I hope all this makes sense, its not so much the specifics i'm struggling
with but the 'bigger picture'.

thanks again

Andy
 
A

AAJ

Hi Fitim

Thanks for the response and the idea, I'll have a good look today. The
question I've got initially though, is if I understand correctly, it will
allow the creation of a single instance, but will the instance (and the
data) remain live between page refreshes, postbacks etc?

thanks again

Andy
 
A

AAJ

I think what I might be looking for is the SessionState facility i've just
stumbled across.

cheers

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top