Error passing Session Variable to SQLDataSource

beatriceumber

New Member
I'm trying to run Project.aspx. Admin.apsx, when the 'VIEW PROFILE' button is clicked, is supposed to create a session "project_id" so the two SQLDataSources get the project_id values from the Session("project_id").I'm getting this error:
ONZoJ.png
Project.aspx\[code\]<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Project.aspx.vb" Inherits="Project" %><%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %><asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div id="project-image"><asp:Image ID="Image1" runat="server" Height="124px" Width="93px" /> <asp:FormView ID="frmViewProject" runat="server" DataKeyNames="project_id" DataSourceID="SqlDataSource1" HorizontalAlign="Justify"> <EditItemTemplate> project_id: <asp:Label ID="project_idLabel1" runat="server" Text='<%# Eval("project_id") %>' /> <br /> project_type: <asp:TextBox ID="project_typeTextBox" runat="server" Text='<%# Bind("project_type") %>' /> <br /> project_start: <asp:TextBox ID="project_startTextBox" runat="server" Text='<%# Bind("project_start") %>' /> <br /> project_finish: <asp:TextBox ID="project_finishTextBox" runat="server" Text='<%# Bind("project_finish") %>' /> <br /> project_duration: <asp:TextBox ID="project_durationTextBox" runat="server" Text='<%# Bind("project_duration") %>' /> <br /> project_budget: <asp:TextBox ID="project_budgetTextBox" runat="server" Text='<%# Bind("project_budget") %>' /> <br /> project_cost: <asp:TextBox ID="project_costTextBox" runat="server" Text='<%# Bind("project_cost") %>' /> <br /> project_name: <asp:TextBox ID="project_nameTextBox" runat="server" Text='<%# Bind("project_name") %>' /> <br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </EditItemTemplate> <EditRowStyle BorderStyle="Solid" Font-Bold="False" Font-Names="Verdana" Font-Overline="False" Font-Size="Small" HorizontalAlign="Right" VerticalAlign="Middle" /> <InsertItemTemplate> project_type: <asp:TextBox ID="project_typeTextBox" runat="server" Text='<%# Bind("project_type") %>' /> <br /> project_start: <asp:TextBox ID="project_startTextBox" runat="server" Text='<%# Bind("project_start") %>' /> <br /> project_finish: <asp:TextBox ID="project_finishTextBox" runat="server" Text='<%# Bind("project_finish") %>' /> <br /> project_duration: <asp:TextBox ID="project_durationTextBox" runat="server" Text='<%# Bind("project_duration") %>' /> <br /> project_budget: <asp:TextBox ID="project_budgetTextBox" runat="server" Text='<%# Bind("project_budget") %>' /> <br /> project_cost: <asp:TextBox ID="project_costTextBox" runat="server" Text='<%# Bind("project_cost") %>' /> <br /> project_name: <asp:TextBox ID="project_nameTextBox" runat="server" Text='<%# Bind("project_name") %>' /> <br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /> &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </InsertItemTemplate> <InsertRowStyle HorizontalAlign="Center" VerticalAlign="Middle" /> <ItemTemplate> project_id: <asp:Label ID="project_idLabel" runat="server" Text='<%# Eval("project_id") %>' /> <br /> project_type: <asp:Label ID="project_typeLabel" runat="server" Text='<%# Bind("project_type") %>' /> <br /> project_start: <asp:Label ID="project_startLabel" runat="server" Text='<%# Bind("project_start") %>' /> <br /> project_finish: <asp:Label ID="project_finishLabel" runat="server" Text='<%# Bind("project_finish") %>' /> <br /> project_duration: <asp:Label ID="project_durationLabel" runat="server" Text='<%# Bind("project_duration") %>' /> <br /> project_budget: <asp:Label ID="project_budgetLabel" runat="server" Text='<%# Bind("project_budget") %>' /> <br /> project_cost: <asp:Label ID="project_costLabel" runat="server" Text='<%# Bind("project_cost") %>' /> <br /> project_name: <asp:Label ID="project_nameLabel" runat="server" Text='<%# Bind("project_name") %>' /> <br /> </ItemTemplate> <RowStyle BorderStyle="None" HorizontalAlign="Left" VerticalAlign="Middle" /> </asp:FormView> <asp:Chart ID="chrtComplete" runat="server" DataMember="DefaultView" DataSourceID="SqlDataSource2" EnableViewState="True"> <series> <asp:Series ChartType="Pie" Legend="Completed" Name="Series1" XValueMember="project_start" YValueMembers="project_finish"> </asp:Series> </series> <chartareas> <asp:ChartArea Name="ChartArea1"> </asp:ChartArea> </chartareas> <Legends> <asp:Legend LegendStyle="Row" Name="Completed"> </asp:Legend> </Legends> <Titles> <asp:Title Name="Project Completion"> </asp:Title> </Titles> </asp:Chart> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [project_start], [project_finish] FROM [projects] WHERE ([project_id] = @project_id)"> <SelectParameters> <asp:SessionParameter Name="project_id" SessionField="project_id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </div> <div id="project-info"> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnStringDb1 %>" SelectCommand="SELECT [project_id], [project_type], [project_start], [project_finish], [project_duration], [project_budget], [project_cost], [project_name] FROM [projects] WHERE ([project_id] = @project_id)"> <SelectParameters> <asp:SessionParameter Name="project_id" SessionField="project_id" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> </div>&nbsp; <br /></asp:Content>\[/code\]Admin.aspx\[code\]Imports System.Data.SqlClientPartial Class Admin Inherits System.Web.UI.Page Protected Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True") Dim searchComm As String = "SELECT username FROM users WHERE CONTAINS (username, @username)" Dim searchSQL As New SqlCommand conn.Open() searchSQL = New SqlCommand(searchComm, conn) searchSQL.Parameters.AddWithValue("@username", txtUserSearch.Text) Dim datareader As SqlDataReader = searchSQL.ExecuteReader() While datareader.Read lstUsers.Items.Add(datareader.Item("username")) End While datareader.Close() conn.Close() End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load End Sub Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpProjects.SelectedIndexChanged Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True") Dim sqlComm As String = "SELECT project_name FROM projects WHERE project_name=@projectname" Dim sqlProjname As New SqlCommand conn.Open() sqlProjname = New SqlCommand(sqlComm, conn) sqlProjname.Parameters.AddWithValue("@projectname", drpProjects.SelectedItem.Text) Dim datareader As SqlDataReader = sqlProjname.ExecuteReader() datareader.Read() If datareader.HasRows Then lblProjName.Text = datareader("project_name").ToString() End If datareader.Close() conn.Close() lblProjName.Visible = True grdProjDetails.Visible = True End Sub Protected Sub btnManageProj_Click(sender As Object, e As EventArgs) Handles btnManageProj.Click MultiView1.SetActiveView(View2) End Sub Protected Sub btnProjSettings_Click(sender As Object, e As EventArgs) Handles btnProjSettings.Click Dim conn2 As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True") Dim sqlComm2 As String = "SELECT project_id FROM projects WHERE project_name=@projectname" Dim sqlProjID As New SqlCommand conn2.Open() sqlProjID = New SqlCommand(sqlComm2, conn2) sqlProjID.Parameters.AddWithValue("@projectname", drpProjects.SelectedItem.Text) Dim datareader As SqlDataReader = sqlProjID.ExecuteReader() datareader.Read() If datareader.HasRows Then Dim UserID As String UserID = datareader("project_id").ToString Session("project_id") = UserID Server.Transfer("Project.aspx", True) End If datareader.Close() conn2.Close() End SubEnd Class\[/code\]Screenshot:
HFDjD.png
What is happening? What is wrong with the code?I am using VS 2012 Professional with SQL-Server 2012 Express
 
Back
Top