• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

Session Value in Detail View giving Null error on update.

Team -

First question here so please forgive me if I do this wrong!  
Trying to have a session variable show up as a value in a detailsview on insert.  I got the text to show in the text box on insert however when I go to insert the new record (with text showing in the textbox from the session) I am getting a  "cannot insert the value NULL for clientcode;........" .  This doesn't really make sense to me, if the text is bound to the clientcode box should it not update?
<InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Session("testsession") %>'></asp:TextBox>
                    </InsertItemTemplate>

Open in new window

0
bluem1
Asked:
bluem1
  • 4
  • 4
1 Solution
 
P_RamprathapCommented:
Could you please show me the insert part your doing .

Ram
0
 
CB_ThirumalaiCommented:
Session("testsession") is coming as null.  Ensure that this value indeed has a value in it and use casting as,
         In C#  (String)Session("testsession") and in VB.Net CStr(Session("testsession"))
Since the session value is coming as null (which means the testsession does not exists in the Session object), you are getting this error.
0
 
bluem1Author Commented:
Thanks for your input.  I tried the Cstr(session("testsession")) but still no go.

What is throwing me is that the session value is showing up in the text box when I go to insert, it just isn't getting inserted.  Putting code below as requested, if you need any more please let me know.  I am including only the code you need so you don't have read a bunch.

Thank you again for your time.
Dewayne
Setting session here for testing.
 
<%  Session("testsession") = "testsessiontext"
        Dim sessiontest = CStr(Session("testsession").ToString())
 
Here is the form insert info:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:blordering_64344ConnectionString %>" 
            SelectCommand="SELECT * FROM [tblparentinfo]" 
            OldValuesParameterFormatString="original_{0}" 
            DeleteCommand="DELETE FROM [tblparentinfo] WHERE [mainid] = @original_mainid AND [clientcode] = @original_clientcode AND [fname] = @original_fname AND [lname] = @original_lname AND (([ssn] = @original_ssn) OR ([ssn] IS NULL AND @original_ssn IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND [los] = @original_los AND (([researchnotes] = @original_researchnotes) OR ([researchnotes] IS NULL AND @original_researchnotes IS NULL)) AND (([ordernotes] = @original_ordernotes) OR ([ordernotes] IS NULL AND @original_ordernotes IS NULL))" 
            InsertCommand="INSERT INTO [tblparentinfo] ([clientcode], [fname], [lname], [ssn], [dob], [los], [researchnotes], [ordernotes]) VALUES (@clientcode, @fname, @lname, @ssn, @dob, @los, @researchnotes, @ordernotes)" 
            
            
            UpdateCommand="UPDATE [tblparentinfo] SET [clientcode] = @clientcode, [fname] = @fname, [lname] = @lname, [ssn] = @ssn, [dob] = @dob, [los] = @los, [researchnotes] = @researchnotes, [ordernotes] = @ordernotes WHERE [mainid] = @original_mainid AND [clientcode] = @original_clientcode AND [fname] = @original_fname AND [lname] = @original_lname AND (([ssn] = @original_ssn) OR ([ssn] IS NULL AND @original_ssn IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND [los] = @original_los AND (([researchnotes] = @original_researchnotes) OR ([researchnotes] IS NULL AND @original_researchnotes IS NULL)) AND (([ordernotes] = @original_ordernotes) OR ([ordernotes] IS NULL AND @original_ordernotes IS NULL))" 
            ConflictDetection="CompareAllValues">
            <DeleteParameters>
                <asp:Parameter Name="original_mainid" Type="Int32" />
                <asp:Parameter Name="original_clientcode" Type="String" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter Name="original_ssn" Type="String" />
                <asp:Parameter Name="original_dob" Type="String" />
                <asp:Parameter Name="original_los" Type="String" />
                <asp:Parameter Name="original_researchnotes" Type="String" />
                <asp:Parameter Name="original_ordernotes" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="clientcode" Type="String" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter Name="ssn" Type="String" />
                <asp:Parameter Name="dob" Type="String" />
                <asp:Parameter Name="los" Type="String" />
                <asp:Parameter Name="researchnotes" Type="String" />
                <asp:Parameter Name="ordernotes" Type="String" />
                <asp:Parameter Name="original_mainid" Type="Int32" />
                <asp:Parameter Name="original_clientcode" Type="String" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter Name="original_ssn" Type="String" />
                <asp:Parameter Name="original_dob" Type="String" />
                <asp:Parameter Name="original_los" Type="String" />
                <asp:Parameter Name="original_researchnotes" Type="String" />
                <asp:Parameter Name="original_ordernotes" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="clientcode" Type="String" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter Name="ssn" Type="String" />
                <asp:Parameter Name="dob" Type="String" />
                <asp:Parameter Name="los" Type="String" />
                <asp:Parameter Name="researchnotes" Type="String" />
                <asp:Parameter Name="ordernotes" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CB_ThirumalaiCommented:
Can you try this?
Dim sessiontest As String = Session("testsession").ToString()

Open in new window

0
 
bluem1Author Commented:
Nope, still a no go.  Same error

Cannot insert the value NULL into column 'clientcode', table 'blordering_64344.dbo.tblparentinfo'; column does not allow nulls. INSERT fails.
The statement has been terminated.

I am beginning to think I have messed this up beyond repair!  May need to back up and restart.
0
 
CB_ThirumalaiCommented:
Where are you setting the Session("testsession") value? Please post the code where you do that.
0
 
bluem1Author Commented:
For testing I was setting it on the current page.  Here is the entire code for the page.  There is no code behind at this time.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" EnableSessionState="True" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <%  Session("testsession") = "testsessiontext"
        Dim sessiontest As String = Session("testsession").ToString()%>
        
        ddd d<br />
        
 
        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" 
            AutoGenerateRows="False" DataKeyNames="mainid" DataSourceID="SqlDataSource1" 
            Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="mainid" HeaderText="mainid" InsertVisible="False" 
                    ReadOnly="True" SortExpression="mainid" />
                <asp:TemplateField HeaderText="clientcode" SortExpression="clientcode">
                    <EditItemTemplate>
                        <asp:TextBox ID="clientcode" runat="server" Text='<%# Session("testsession") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="clientcode" runat="server" Text='<%# Session("testsession")%>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Session("testsession") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
                <asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
                <asp:BoundField DataField="ssn" HeaderText="ssn" SortExpression="ssn" />
                <asp:BoundField DataField="dob" HeaderText="dob" SortExpression="dob" />
                <asp:BoundField DataField="los" HeaderText="los" SortExpression="los" />
                <asp:BoundField DataField="researchnotes" HeaderText="researchnotes" 
                    SortExpression="researchnotes" />
                <asp:BoundField DataField="ordernotes" HeaderText="ordernotes" 
                    SortExpression="ordernotes" />
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
        
 
        <br />
        afs  <%=sessiontest%>  df<br />
        <br />
        <asp:TextBox ID="newbox" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:blordering_64344ConnectionString %>" 
            SelectCommand="SELECT * FROM [tblparentinfo]" 
            OldValuesParameterFormatString="original_{0}" 
            DeleteCommand="DELETE FROM [tblparentinfo] WHERE [mainid] = @original_mainid AND [clientcode] = @original_clientcode AND [fname] = @original_fname AND [lname] = @original_lname AND (([ssn] = @original_ssn) OR ([ssn] IS NULL AND @original_ssn IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND [los] = @original_los AND (([researchnotes] = @original_researchnotes) OR ([researchnotes] IS NULL AND @original_researchnotes IS NULL)) AND (([ordernotes] = @original_ordernotes) OR ([ordernotes] IS NULL AND @original_ordernotes IS NULL))" 
            InsertCommand="INSERT INTO [tblparentinfo] ([clientcode], [fname], [lname], [ssn], [dob], [los], [researchnotes], [ordernotes]) VALUES (@clientcode, @fname, @lname, @ssn, @dob, @los, @researchnotes, @ordernotes)" 
            
            
            UpdateCommand="UPDATE [tblparentinfo] SET [clientcode] = @clientcode, [fname] = @fname, [lname] = @lname, [ssn] = @ssn, [dob] = @dob, [los] = @los, [researchnotes] = @researchnotes, [ordernotes] = @ordernotes WHERE [mainid] = @original_mainid AND [clientcode] = @original_clientcode AND [fname] = @original_fname AND [lname] = @original_lname AND (([ssn] = @original_ssn) OR ([ssn] IS NULL AND @original_ssn IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND [los] = @original_los AND (([researchnotes] = @original_researchnotes) OR ([researchnotes] IS NULL AND @original_researchnotes IS NULL)) AND (([ordernotes] = @original_ordernotes) OR ([ordernotes] IS NULL AND @original_ordernotes IS NULL))" 
            ConflictDetection="CompareAllValues">
            <DeleteParameters>
                <asp:Parameter Name="original_mainid" Type="Int32" />
                <asp:Parameter Name="original_clientcode" Type="String" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter Name="original_ssn" Type="String" />
                <asp:Parameter Name="original_dob" Type="String" />
                <asp:Parameter Name="original_los" Type="String" />
                <asp:Parameter Name="original_researchnotes" Type="String" />
                <asp:Parameter Name="original_ordernotes" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="clientcode" Type="String" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter Name="ssn" Type="String" />
                <asp:Parameter Name="dob" Type="String" />
                <asp:Parameter Name="los" Type="String" />
                <asp:Parameter Name="researchnotes" Type="String" />
                <asp:Parameter Name="ordernotes" Type="String" />
                <asp:Parameter Name="original_mainid" Type="Int32" />
                <asp:Parameter Name="original_clientcode" Type="String" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter Name="original_ssn" Type="String" />
                <asp:Parameter Name="original_dob" Type="String" />
                <asp:Parameter Name="original_los" Type="String" />
                <asp:Parameter Name="original_researchnotes" Type="String" />
                <asp:Parameter Name="original_ordernotes" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="clientcode" Type="String" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter Name="ssn" Type="String" />
                <asp:Parameter Name="dob" Type="String" />
                <asp:Parameter Name="los" Type="String" />
                <asp:Parameter Name="researchnotes" Type="String" />
                <asp:Parameter Name="ordernotes" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
    
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="mainid" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="mainid" HeaderText="mainid" InsertVisible="False" 
                    ReadOnly="True" SortExpression="mainid" />
                <asp:BoundField DataField="clientcode" HeaderText="clientcode" 
                    SortExpression="clientcode" />
                <asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
                <asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
                <asp:BoundField DataField="ssn" HeaderText="ssn" 
                    SortExpression="ssn" />
                <asp:BoundField DataField="dob" HeaderText="dob" 
                    SortExpression="dob" />
                <asp:BoundField DataField="los" HeaderText="los" SortExpression="los" />
                <asp:BoundField DataField="researchnotes" HeaderText="researchnotes" 
                    SortExpression="researchnotes" />
                <asp:BoundField DataField="ordernotes" HeaderText="ordernotes" 
                    SortExpression="ordernotes" />
            </Columns>
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Open in new window

0
 
CB_ThirumalaiCommented:
I don't think this will work.  It is an incorrect syntax.  DetailsView item template needs to be accessed from within the Item Bound event.  Refer this link
http://msdn.microsoft.com/en-us/library/bb288033.aspx
0
 
bluem1Author Commented:
Yes.  Looks like you are right.

To get around this I went with a forms view and created a class file that I founnd at:

http://codeforeternity.com/blogs/technology/archive/2007/12/19/handling-asp-net-session-variables-efficiently.aspx 

Seems to be working great.
Thank you again for all your help.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now