Search:
Namespaces
Discussions
.NET v1.1
Feedback
Help with datasets and sessions
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngdatagridrepeaterdatalist' list
.
edp
Hi All :
I am having trouble with the code below :
It is fine if I use sessions and add the dataset ds to the session.
Should I be able to access the dataset, datatables and so on, if I defined them as global (that is, outside the method declaration) ??
Can someone help ???
CHEERS !!
Sum Pun
************
DataSet
ds;=20
DataTable
dt;=20
DataView
dv;=20
SqlDataAdapter
oleDa ;=20
void Page_Load(Object sender,
EventArgs
e)=20
{=20
if (!IsPostBack)
{=20
string strConn =3D "server=3D(local);database=3Dpubs;Trusted_Connection=3Dyes";=20
string strSQL =3D "SELECT id, item from item" ;=20
SqlConnection
oleConn =3D new
SqlConnection
(strConn);=20
oleDa =3D new
SqlDataAdapter
(strSQL, oleConn);=20
ds =3D new
DataSet
();=20
dt =3D new
DataTable
();=20
dt =3D ds.Tables.Add("dt");=20
oleDa.Fill(ds, "dt");=20
dv =3D new
DataView
(dt);=20
dv.Sort=3D"Item";=20
MyDataGrid.DataSource =3D dv;=20
MyDataGrid.DataBind();=20
}=20
}=20
void ClickMe(object sender ,
EventArgs
e)=20
{=20
dv.RowFilter =3D "id=3D1"; =20
MyDataGrid.DataSource =3D dv;=20
MyDataGrid.DataBind();=20
}=20
**************
------=_NextPart_000_000E_01C23C95.4F502000
Reply to this message...
Tim Musschoot
In general, this is not a good idea, except if you know very good what you
are doing. Global variables only are available at one certain moment the
page is run at the server. If you do a postback, you'll have to
re-initialize. In the ClickMe method, 'dv' is not initialized (NULL), so it
cannot work. You'll have to re-initialize all members. What you can do is
place this initialization code in the Page Constructor... (this makes it
automated...)
Something else: placing a dataset in a Session variable is a very very bad
idea, except when only one or a few users are using your site. This will
take a huge amount of resources ! I suggest you store them in a database
(sql-server) !
Best Regards,
Tim Musschoot
Software Engineer
AspFriends Moderation Team
http://www.aspfriends.com
Click here to reveal e-mail address
http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht-----
Van: edp [mailto:
Click here to reveal e-mail address
]
Verzonden: maandag 5 augustus 2002 9:32
Aan: aspngDataGridRepeaterDatalist
Onderwerp: [aspngdatagridrepeaterdatalist] Help with datasets and sessions
Hi All :
I am having trouble with the code below :
It is fine if I use sessions and add the dataset ds to the session.
Should I be able to access the dataset, datatables and so on, if I defined
them as global (that is, outside the method declaration) ??
Can someone help ???
CHEERS !!
Sum Pun
************
DataSet
ds;
DataTable
dt;
DataView
dv;
SqlDataAdapter
oleDa ;
void Page_Load(Object sender,
EventArgs
e)
{
if (!IsPostBack)
{
string strConn "server=(local);database=pubs;Trusted_Connection=yes";
string strSQL = "SELECT id, item from item" ;
SqlConnection
oleConn = new
SqlConnection
(strConn);
oleDa = new
SqlDataAdapter
(strSQL, oleConn);
ds = new
DataSet
();
dt = new
DataTable
();
dt = ds.Tables.Add("dt");
oleDa.Fill(ds, "dt");
dv = new
DataView
(dt);
dv.Sort="Item";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
}
void ClickMe(object sender ,
EventArgs
e)
{
dv.RowFilter = "id=1";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
**************
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp JOIN/QUIT
Reply to this message...
Doug J. Nelson
Consider using viewstate instead.
=20
DataSet
ds;=20
DataTable
dt;=20
DataView
dv;=20
SqlDataAdapter
oleDa ;=20
void Page_Load(Object sender,
EventArgs
e)=20
{=20
if (!IsPostBack)
{=20
string strConn =3D
"server=3D(local);database=3Dpubs;Trusted_Connection=3Dyes";=20
string strSQL =3D "SELECT id, item from item" ;=20
SqlConnection
oleConn =3D new
SqlConnection
(strConn);=20
oleDa =3D new
SqlDataAdapter
(strSQL, oleConn);=20
ds =3D new
DataSet
();=20
dt =3D new
DataTable
();=20
dt =3D ds.Tables.Add("dt");=20
oleDa.Fill(ds, "dt");=20
dv =3D new
DataView
(dt);=20
dv.Sort=3D"Item";=20
MyDataGrid.DataSource =3D dv;=20
MyDataGrid.DataBind();=20
=20
ViewState["mydv"] =3D dv;
}=20
}=20
void ClickMe(object sender ,
EventArgs
e)=20
{=20
if (ViewState["mydv"] !=3D null)
{
DataView
dv =3D (DataView)ViewState["mydv"];
dv.RowFilter =3D "id=3D1"; =20
MyDataGrid.DataSource =3D dv;=20
MyDataGrid.DataBind();=20
}
}=20
=20
Viewstate allows you retain values when the pages are reposted to
themselves as the example with your code. The comment on using session
state was correct because of the resoures consumed on the server. In
the example you give, you already have the information in the database (
sql server) and it is hands down, the best place to store this
information. View state stores the information in the client page so
the only thing consumed is bandwidth.
=20
Hope this helps.
=20
=20
Doug Nelson
SynApp north
305 Arch St
Cloquet, MN 55720
(218) 878 - 2015=20
(218) 878 - 2019 fax
=20
Reply to this message...
Matt Hauser
Of course, you could save session state to the database. This way you
get the session object use and the data is saved to the DB between
pages.
-Matt-
-----Original Message-----
From: Tim Musschoot [mailto:
Click here to reveal e-mail address
]
Sent: Monday, August 05, 2002 6:15 AM
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] RE: Help with datasets and
sessions
In general, this is not a good idea, except if you know very good what
you are doing. Global variables only are available at one certain
moment the page is run at the server. If you do a postback, you'll have
to re-initialize. In the ClickMe method, 'dv' is not initialized
(NULL), so it cannot work. You'll have to re-initialize all members.
What you can do is place this initialization code in the Page
Constructor... (this makes it automated...)
Something else: placing a dataset in a Session variable is a very very
bad idea, except when only one or a few users are using your site. This
will take a huge amount of resources ! I suggest you store them in a
database (sql-server) !
Best Regards,
Tim Musschoot
Software Engineer
AspFriends Moderation Team
http://www.aspfriends.com
<
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/>
Click here to reveal e-mail address
http://www.aspalliance.com/timmusschoot
-----Oorspronkelijk bericht-----
Van: edp [mailto:
Click here to reveal e-mail address
]
Verzonden: maandag 5 augustus 2002 9:32
Aan: aspngDataGridRepeaterDatalist
Onderwerp: [aspngdatagridrepeaterdatalist] Help with datasets and
sessions
Hi All :
I am having trouble with the code below :
It is fine if I use sessions and add the dataset ds to the session.
Should I be able to access the dataset, datatables and so on, if I
defined them as global (that is, outside the method declaration) ??
Can someone help ???
CHEERS !!
Sum Pun
************
DataSet
ds;
DataTable
dt;
DataView
dv;
SqlDataAdapter
oleDa ;
void Page_Load(Object sender,
EventArgs
e)
{
if (!IsPostBack)
{
string strConn "server=(local);database=pubs;Trusted_Connection=yes";
string strSQL = "SELECT id, item from item" ;
SqlConnection
oleConn = new
SqlConnection
(strConn);
oleDa = new
SqlDataAdapter
(strSQL, oleConn);
ds = new
DataSet
();
dt = new
DataTable
();
dt = ds.Tables.Add("dt");
oleDa.Fill(ds, "dt");
dv = new
DataView
(dt);
dv.Sort="Item";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
}
void ClickMe(object sender ,
EventArgs
e)
{
dv.RowFilter = "id=1";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
**************
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR
ID |
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp JOIN/QUIT
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
YOUR ID |
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp JOIN/QUIT
Reply to this message...
John John
> Something else: placing a dataset in a Session variable is a very very bad
idea, except when only one or a few users are
> using your site. This will take a huge amount of resources ! I suggest
you store them in a database (sql-server) !
I do not agree on that. I might even be the best place to store your
datas...
The asp.net framework got ride with most of the limitations you had with
ASP, we could discuss in details about that
but other ressources in the help or on the web will do better then I :)
John.
Reply to this message...
John John
or you leave it in the session and put your session mode to database persist
mode :)
-----Original Message-----
From: Matt Hauser [mailto:
Click here to reveal e-mail address
]
Sent: lundi 5 août 2002 14:09
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] RE: Help with datasets and sessions
Of course, you could save session state to the database. This way you get
the session object use and the data is saved to the DB between pages.
-Matt-
-----Original Message-----
From: Tim Musschoot [mailto:
Click here to reveal e-mail address
]
Sent: Monday, August 05, 2002 6:15 AM
To: aspngDataGridRepeaterDatalist
Subject: [aspngdatagridrepeaterdatalist] RE: Help with datasets and sessions
In general, this is not a good idea, except if you know very good what you
are doing. Global variables only are available at one certain moment the
page is run at the server. If you do a postback, you'll have to
re-initialize. In the ClickMe method, 'dv' is not initialized (NULL), so it
cannot work. You'll have to re-initialize all members. What you can do is
place this initialization code in the Page Constructor... (this makes it
automated...)
Something else: placing a dataset in a Session variable is a very very bad
idea, except when only one or a few users are using your site. This will
take a huge amount of resources ! I suggest you store them in a database
(sql-server) !
Best Regards,
Tim Musschoot
Software Engineer
AspFriends Moderation Team
http://www.aspfriends.com
<
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/>
Click here to reveal e-mail address
http://www.aspalliance.com/timmusschoot
<
http://www.aspalliance.com/timmusschoot
>
-----Oorspronkelijk bericht-----
Van: edp [mailto:
Click here to reveal e-mail address
]
Verzonden: maandag 5 augustus 2002 9:32
Aan: aspngDataGridRepeaterDatalist
Onderwerp: [aspngdatagridrepeaterdatalist] Help with datasets and sessions
Hi All :
I am having trouble with the code below :
It is fine if I use sessions and add the dataset ds to the session.
Should I be able to access the dataset, datatables and so on, if I defined
them as global (that is, outside the method declaration) ??
Can someone help ???
CHEERS !!
Sum Pun
************
DataSet
ds;
DataTable
dt;
DataView
dv;
SqlDataAdapter
oleDa ;
void Page_Load(Object sender,
EventArgs
e)
{
if (!IsPostBack)
{
string strConn = "server=(local);database=pubs;Trusted_Connection=yes";
string strSQL = "SELECT id, item from item" ;
SqlConnection
oleConn = new
SqlConnection
(strConn);
oleDa = new
SqlDataAdapter
(strSQL, oleConn);
ds = new
DataSet
();
dt = new
DataTable
();
dt = ds.Tables.Add("dt");
oleDa.Fill(ds, "dt");
dv = new
DataView
(dt);
dv.Sort="Item";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
}
void ClickMe(object sender ,
EventArgs
e)
{
dv.RowFilter = "id=1";
MyDataGrid.DataSource = dv;
MyDataGrid.DataBind();
}
**************
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR ID |
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp JOIN/QUIT
| [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
= YOUR
ID |
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp
= JOIN/QUIT | [aspngdatagridrepeaterdatalist] member
Click here to reveal e-mail address
YOUR ID |
http://www.aspfriends.com
/" target="_blank">
http://www.aspfriends.com
/aspfriends/aspngdatagridrepeaterdatalist.asp JOIN/QUIT
Reply to this message...
System.Data.DataSet
System.Data.DataTable
System.Data.DataView
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.EventArgs
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com