web 2.0

ASP.NET(vb.net) Session & Object Value

ASP.NET(vb.net) Session & Object Value - Session & Object Value : The learn and script how to use Session and Object variable.

ShotDev Focus:
- ASP.NET(vb.net) Session & Object Value

Example

AspNetSessionObject.aspx

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

'*** Create Object Session ***'
Dim objFSO, objStream As Object
objFSO = Server.CreateObject("Scripting.FileSystemObject")

'*** Used Session ***'
Session("mySession") = objFSO

objStream = Session("mySession").OpenTextFile(Server.MapPath("MyFiles/shotdev.txt"))

Do Until objStream.AtEndOfStream
Me.lblText1.Text = Me.lblText1.Text & objStream.ReadLine & "<br>"
Loop
objStream.Close()
objStream = Nothing

'*** New Control & Session ***'
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"
objConn = New OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()

'*** GridView Session ***'
Dim myGridView As New GridView
Session("myControl") = myGridView

Dim myCtrl As GridView = CType(Session("myControl"), GridView)

With myCtrl
.AutoGenerateColumns = True
.DataSource = dtReader
.DataBind()
End With

'*** Load Control To Label ***'
Me.lblText2.Controls.Add(myCtrl)

dtReader.Close()
dtReader = Nothing
objConn.Close()
objConn = Nothing

End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form runat="server">
<asp:Label id="lblText1" runat="server"></asp:Label>
<hr />
<asp:Label id="lblText2" runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) Session & Object Value
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.