From: Mario on
I need an advice for a most common and memory efficient method. I collect
data on a three pages (1,2,3 step) and need to save data to database. Is it
ok to open connection and insert data on every page, or to somehow save to
global variables and then save on a last page ?


From: Mario on

"Mario" <mzupan(a)vup.hr> wrote in message
news:i09jnj$pve$1(a)news1.carnet.hr...
>I need an advice for a most common and memory efficient method. I collect
>data on a three pages (1,2,3 step) and need to save data to database. Is
>it ok to open connection and insert data on every page, or to somehow save
>to global variables and then save on a last page ?
>

Correct me if I'm wrong but in a
Case1: saving data to database, open and close connection - I need to find
out the ID and that may cause some problem if two users inserted in the same
time:

SqlCommand id_cmd = new SqlCommand("select scope_identity() as id",
connection);

Object new_id = id_cmd.ExecuteScalar();

Case 2: I use session variable but it acts on a strange way, sometimes I got
a null without any particular reason.


From: Mr. Arnold on
Mario wrote:
> I need an advice for a most common and memory efficient method. I collect
> data on a three pages (1,2,3 step) and need to save data to database. Is it
> ok to open connection and insert data on every page, or to somehow save to
> global variables and then save on a last page ?
>
>

You should use an object with public properties to hold the data from
each page and pass the object as a session variable between pages.

If you have some flag in the object that it has indicated the user has
hit the last page, then you can go backwards to the other pages.

Up until the point of hitting the last page, the Save button on the two
pages prior to the last page will have the Save button hidden on the
page. User hits the last page, the indicator in object is set to
indicate last page has been hit, then you unhide the Save button on the
the first two pages so the user can save the data from any page at that
point.

Everything is kept in the session object, and controls for each page are
populated from the object, not using a control's view state --
(disabled).

Of course, the Save button on each page should have the same logic to
validate the object before it's persisted to the database and the same
persist logic.

The Save button on each page being hidden and unhidden is for the
creation process.

If it's the maintenance process, the the Save button is unhidden out the
gate for each page with the first page being show to the user being page #1.

You should look into using a tab control that allows the user to move to
each page effortlessly when the last page is reached in the creation
process, and the tab control is enabled on each page in the maintenancee
process out the gate.
From: Mr. Arnold on
Mario wrote:
> "Mario" <mzupan(a)vup.hr> wrote in message
> news:i09jnj$pve$1(a)news1.carnet.hr...
>> I need an advice for a most common and memory efficient method. I collect
>> data on a three pages (1,2,3 step) and need to save data to database. Is
>> it ok to open connection and insert data on every page, or to somehow save
>> to global variables and then save on a last page ?
>>
>
> Correct me if I'm wrong but in a
> Case1: saving data to database, open and close connection - I need to find
> out the ID and that may cause some problem if two users inserted in the same
> time:
>
If you had some kind of problem, then a SQL Exception is thrown and
nothing is saved there is no ID to look at.

If you use ADO.NET Transaction using a Trans.Setcomplete after the
successful processing path has completed is a best practice.

> SqlCommand id_cmd = new SqlCommand("select scope_identity() as id",
> connection);
>
> Object new_id = id_cmd.ExecuteScalar();

The problem of two user inserting at the same time will never happen if
using ADO.NET Transaction and wrapping the whole process in a
transaction is a best practice.

>
> Case 2: I use session variable but it acts on a strange way, sometimes I got
> a null without any particular reason.
>
>

It's most likely the user sat on a page and did nothing, a Session
Timeout happened and the Session variable is lost for the session. The
variable is dead/null and the session is dead at that point, and the
user has to start over.

If this is a problem, then you need to find a way to save the session
data to a database table, so that if the session has timed-out, you can
go to the database and get the session data and put the session data
back into session to allow the Web application to continue.

From: Mario on

"Mr. Arnold" <Arnold(a)Arnold.com> wrote in message
news:%23DHBERrFLHA.5472(a)TK2MSFTNGP04.phx.gbl...
> Mario wrote:
>> I need an advice for a most common and memory efficient method. I collect
>> data on a three pages (1,2,3 step) and need to save data to database. Is
>> it ok to open connection and insert data on every page, or to somehow
>> save to global variables and then save on a last page ?
>
> You should use an object with public properties to hold the data from each
> page and pass the object as a session variable between pages.
>
> If you have some flag in the object that it has indicated the user has hit
> the last page, then you can go backwards to the other pages.
>
> Up until the point of hitting the last page, the Save button on the two
> pages prior to the last page will have the Save button hidden on the page.
> User hits the last page, the indicator in object is set to indicate last
> page has been hit, then you unhide the Save button on the the first two
> pages so the user can save the data from any page at that point.
>
> Everything is kept in the session object, and controls for each page are
> populated from the object, not using a control's view state --
> (disabled).
>
> Of course, the Save button on each page should have the same logic to
> validate the object before it's persisted to the database and the same
> persist logic.
>
> The Save button on each page being hidden and unhidden is for the creation
> process.
>
> If it's the maintenance process, the the Save button is unhidden out the
> gate for each page with the first page being show to the user being page
> #1.
>
> You should look into using a tab control that allows the user to move to
> each page effortlessly when the last page is reached in the creation
> process, and the tab control is enabled on each page in the maintenancee
> process out the gate.

You give me idea with the Tab control, so I think I that multiview will
solve the problem, to avoid session variables.
Still don't see the purpose of ADO.NET and also LINQ. They are also use
dataset, connection which I use for editing database, so they are to
imaginary terms for me.
Thanks