| | |
Session variable
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 2
Reputation:
Solved Threads: 0
I intend to use session variable to capture searching keywords and catagory input by user. I created datatable dTable to store "catagory", "keyword" and "ID" and save it into session variable session("MyCat") when page is firstly loaded.
If it is still within same session time frame, any new input will be automatically added into this datatable and session variable updated as well.
Anyway, my program can not get through as it is captured error in
dim dr as DataRow=dTable.NewRow() in my else statement.
May I know what is wrong with my coding in Sub Submit portion and how this can be implemented efficiently in ASP.NET?
<%@ Page Language="VB" EnableSessionState=true %>
<%@ Register TagPrefix="CityLibrary" TagName="Header_search" Src="..\include/header_search.ascx" %>
<%@ Register TagPrefix="CityLibrary" TagName="bar_empty" Src="..\include/bar_empty.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Submit(Sender As Object, e As EventArgs)
if NOT Page.IsPostBack then
dim dTable as New DataTable("mySearch")
dTable.Columns.Add("catagory", System.Type.getType("System.String"))
dTable.Columns.Add("keyword", System.Type.getType("System.String"))
dTable.Columns.Add("ID", System.Type.getType("System.Int32"))
dTable.Columns("ID").AutoIncrement=True
Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0)= dTable.Columns("ID")
dTable.PrimaryKey = PrimaryKeyColumns
dim dr as DataRow=dTable.NewRow()
dr(0)=Listbox1.SelectedItem.value
dr(1)=tbtext.Text
dTable.Rows.Add(dr)
session("myCat")= dTable
else
dim dTable as New DataTable
dTable= session("myCat")
dim dr as DataRow=dTable.NewRow()
dr(0)=Listbox1.SelectedItem.value
dr(1)=tbtext.Text
dTable.Rows.Add(dr)
session("myCat")= dTable
end if
session.Timeout=2
dim keyword as String
dim catagory as String
dim objitem as new CityLibrary.libraryItem
keyword = tbtext.Text
catagory = Listbox1.SelectedItem.value
dim objReader as OleDbDataReader
objReader = objitem.GetLibraryItemGeneral(catagory,keyword)
session("mydata")=objreader
objReader.Close()
objitem.Dispose
Response.Redirect("searchresult.aspx")
End Sub
</script>
<html><body>
<table height="100%" cellspacing=0 cellpadding=0 width="100%">
<CityLibrary:Header_Search runat="server"/>
<tr height="100%">
<CityLibrary:bar_empty runat="server"/>
<td align=left valign="top" width=100% nowrap>
<table height="100%" valign="top" align="left" cellspacing=0 cellpadding=0 width="100%">
<tr height="100%" valign="top">
<td nowrap>
<table cellspacing=0 cellpadding=0 width="100%">
<tr>
<td valign="top">
<br>
<center>
<form action="Basicsearchmain.aspx" runat="server">
<h3> Name: <asp:Textbox id="tbText" type=text runat="Server"/><br><br>
UserGroup: <asp:Listbox runat="server" id="listbox1" width="200" rows="1"
SelectionMode="Single">
<asp:Listitem value="title">Title Keywords</asp:Listitem>
<asp:Listitem value="name">Author Last Name or FIrst Name</asp:Listitem>
<asp:Listitem value="subject">Subject Keywords</asp:Listitem>
<asp:Listitem value="kidstitle"> Kids' Reading Title</asp:Listitem>
<asp:Listitem value="kidssubject">Kids' reading Subject</asp:Listitem>
<asp:Listitem value="periodical">Periodical title</asp:Listitem>
<asp:Listitem value="keywordall">All Keywords</asp:Listitem>
</asp:Listbox><p>
<ASP:Button id="btSubmit" onclick="Submit" text="Lookup" runat="server"/>
</h3>
</form>
</center>
<hr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body></html>
If it is still within same session time frame, any new input will be automatically added into this datatable and session variable updated as well.
Anyway, my program can not get through as it is captured error in
dim dr as DataRow=dTable.NewRow() in my else statement.
May I know what is wrong with my coding in Sub Submit portion and how this can be implemented efficiently in ASP.NET?
<%@ Page Language="VB" EnableSessionState=true %>
<%@ Register TagPrefix="CityLibrary" TagName="Header_search" Src="..\include/header_search.ascx" %>
<%@ Register TagPrefix="CityLibrary" TagName="bar_empty" Src="..\include/bar_empty.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Submit(Sender As Object, e As EventArgs)
if NOT Page.IsPostBack then
dim dTable as New DataTable("mySearch")
dTable.Columns.Add("catagory", System.Type.getType("System.String"))
dTable.Columns.Add("keyword", System.Type.getType("System.String"))
dTable.Columns.Add("ID", System.Type.getType("System.Int32"))
dTable.Columns("ID").AutoIncrement=True
Dim PrimaryKeyColumns(0) As DataColumn
PrimaryKeyColumns(0)= dTable.Columns("ID")
dTable.PrimaryKey = PrimaryKeyColumns
dim dr as DataRow=dTable.NewRow()
dr(0)=Listbox1.SelectedItem.value
dr(1)=tbtext.Text
dTable.Rows.Add(dr)
session("myCat")= dTable
else
dim dTable as New DataTable
dTable= session("myCat")
dim dr as DataRow=dTable.NewRow()
dr(0)=Listbox1.SelectedItem.value
dr(1)=tbtext.Text
dTable.Rows.Add(dr)
session("myCat")= dTable
end if
session.Timeout=2
dim keyword as String
dim catagory as String
dim objitem as new CityLibrary.libraryItem
keyword = tbtext.Text
catagory = Listbox1.SelectedItem.value
dim objReader as OleDbDataReader
objReader = objitem.GetLibraryItemGeneral(catagory,keyword)
session("mydata")=objreader
objReader.Close()
objitem.Dispose
Response.Redirect("searchresult.aspx")
End Sub
</script>
<html><body>
<table height="100%" cellspacing=0 cellpadding=0 width="100%">
<CityLibrary:Header_Search runat="server"/>
<tr height="100%">
<CityLibrary:bar_empty runat="server"/>
<td align=left valign="top" width=100% nowrap>
<table height="100%" valign="top" align="left" cellspacing=0 cellpadding=0 width="100%">
<tr height="100%" valign="top">
<td nowrap>
<table cellspacing=0 cellpadding=0 width="100%">
<tr>
<td valign="top">
<br>
<center>
<form action="Basicsearchmain.aspx" runat="server">
<h3> Name: <asp:Textbox id="tbText" type=text runat="Server"/><br><br>
UserGroup: <asp:Listbox runat="server" id="listbox1" width="200" rows="1"
SelectionMode="Single">
<asp:Listitem value="title">Title Keywords</asp:Listitem>
<asp:Listitem value="name">Author Last Name or FIrst Name</asp:Listitem>
<asp:Listitem value="subject">Subject Keywords</asp:Listitem>
<asp:Listitem value="kidstitle"> Kids' Reading Title</asp:Listitem>
<asp:Listitem value="kidssubject">Kids' reading Subject</asp:Listitem>
<asp:Listitem value="periodical">Periodical title</asp:Listitem>
<asp:Listitem value="keywordall">All Keywords</asp:Listitem>
</asp:Listbox><p>
<ASP:Button id="btSubmit" onclick="Submit" text="Lookup" runat="server"/>
</h3>
</form>
</center>
<hr>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body></html>
The problem is this line of code
dTable= session("myCat")
you are trying to put a session varible datatype to a Datatable datatype (make sense?) but you can't do this implicitly, you must cast it to the datatype you want.
so it should be something like this
dTable = CType(Session("myCat"), DataTable)
Hope this helps
Happy coding
dTable= session("myCat")
you are trying to put a session varible datatype to a Datatable datatype (make sense?) but you can't do this implicitly, you must cast it to the datatype you want.
so it should be something like this
dTable = CType(Session("myCat"), DataTable)
Hope this helps
Happy coding
![]() |
Similar Threads
- session variable error (PHP)
- calling session variable (ASP.NET)
- Session Variable clashing (ASP.NET)
- Losing session variable problem...help! (ASP)
- session variable undefined in MX 6.1, works in CF 5 (ColdFusion)
- session variable:again (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Error while building asp.net solution
- Next Thread: DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects opera order problem ratings redirect registration relationaldatabases rotatepage search security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopemnt webdevelopment xml xsl





