Solved

Getting error on ItemInserting event on Formview

Posted on 2014-04-22
7
249 Views
Last Modified: 2014-04-24
Hi,
I have a formview on my web page bound to a sql data source.  When I try to Insert a new record I get an error message that I cannot insert a null value in the adj_description column.  I'm not sure what I'm doing wrong; everything looks okay.

I've attached my sqldatasource code and my formview code

 <asp:FormView ID="fvInsertNewAdjusment" runat="server" 
                DataSourceID="AdjustmenttSqlDataSource" DefaultMode="Insert">
                <EditItemTemplate>
                    AdjID:
                    <asp:Label ID="AdjIDLabel1" runat="server" Text='<%# Eval("AdjID") %>' />
                    <br />
                    Lockbox:
                    <asp:TextBox ID="LockboxTextBox" runat="server" Text='<%# Bind("Lockbox") %>' />
                    <br />
                    Credit_Date:
                    <asp:TextBox ID="Credit_DateTextBox" runat="server" 
                        Text='<%# Bind("Credit_Date") %>' />
                    <br />
                    Adj_Description:
                    <asp:TextBox ID="Adj_DescriptionTextBox" runat="server" 
                        Text='<%# Bind("Adj_Description") %>' />
                    <br />
                    Adj_Amt:
                    <asp:TextBox ID="Adj_AmtTextBox" runat="server" Text='<%# Bind("Adj_Amt") %>' />
                    <br />
                    Created_By:
                    <asp:TextBox ID="Created_ByTextBox" runat="server" 
                        Text='<%# Bind("Created_By") %>' />
                    <br />
                    Create_Date:
                    <asp:TextBox ID="Create_DateTextBox" runat="server" 
                        Text='<%# Bind("Create_Date") %>' />
                    <br />
                    Last_Modified_By:
                    <asp:TextBox ID="Last_Modified_ByTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' />
                    <br />
                    Last_Modified_Date:
                    <asp:TextBox ID="Last_Modified_DateTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' />
                    <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>
                <InsertItemTemplate>
                    <table style="width:35%;">
                        <tr>
                            <td class="style6">
                                Lockbox:
                            </td>
                            <td>
                                <asp:TextBox ID="LockboxTextBox" runat="server" Text='<%# Bind("Lockbox") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Credit Date:</td>
                            <td>
                                <asp:TextBox ID="Credit_DateTextBox" runat="server" 
                                    Text='<%# Bind("Credit_Date", "{0:d}") %>' ReadOnly="True" />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Adjustment Description:
                            </td>
                            <td>
                                <asp:TextBox ID="Adj_DescriptionTextBox" runat="server" 
                                    Text='<%# Bind("Adj_Description") %>' Width="380px" Height="29px" />
                            </td>
                        </tr>
                        <tr>
                            <td class="style6">
                                Adjustment Amt:
                            </td>
                            <td>
                                <asp:TextBox ID="Adj_AmtTextBox" runat="server" Text='<%# Bind("Adj_Amt", "{0:N}") %>' 
                                    style="margin-left: 1px" />
                            </td>
                        </tr>
                    </table>
                    &nbsp;<asp:TextBox ID="Created_ByTextBox" runat="server" 
                        Text='<%# Bind("Created_By") %>' Visible="False" />
                    <asp:TextBox ID="Create_DateTextBox" runat="server" 
                        Text='<%# Bind("Create_Date") %>' Visible="False" />
                    <asp:TextBox ID="Last_Modified_ByTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' Visible="False" />
                    <asp:TextBox ID="Last_Modified_DateTextBox" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' Visible="False" />
                    <br />
                    &nbsp;<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 BackColor="White" BorderColor="Black" BorderStyle="Solid" />
                <ItemTemplate>
                    AdjID:
                    <asp:Label ID="AdjIDLabel" runat="server" Text='<%# Eval("AdjID") %>' />
                    <br />
                    Lockbox:
                    <asp:Label ID="LockboxLabel" runat="server" Text='<%# Bind("Lockbox") %>' />
                    <br />
                    Credit_Date:
                    <asp:Label ID="Credit_DateLabel" runat="server" 
                        Text='<%# Bind("Credit_Date") %>' />
                    <br />
                    Adj_Description:
                    <asp:Label ID="Adj_DescriptionLabel" runat="server" 
                        Text='<%# Bind("Adj_Description") %>' />
                    <br />
                    Adj_Amt:
                    <asp:Label ID="Adj_AmtLabel" runat="server" Text='<%# Bind("Adj_Amt") %>' />
                    <br />
                    Created_By:
                    <asp:Label ID="Created_ByLabel" runat="server" 
                        Text='<%# Bind("Created_By") %>' />
                    <br />
                    Create_Date:
                    <asp:Label ID="Create_DateLabel" runat="server" 
                        Text='<%# Bind("Create_Date") %>' />
                    <br />
                    Last_Modified_By:
                    <asp:Label ID="Last_Modified_ByLabel" runat="server" 
                        Text='<%# Bind("Last_Modified_By") %>' />
                    <br />
                    Last_Modified_Date:
                    <asp:Label ID="Last_Modified_DateLabel" runat="server" 
                        Text='<%# Bind("Last_Modified_Date") %>' />
                    <br />
                    <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                        CommandName="New" Text="New" />
                </ItemTemplate>
            </asp:FormView>

Open in new window


 <asp:SqlDataSource ID="AdjustmenttSqlDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:FMSConnectionString %>" 
                InsertCommand="INSERT INTO FMS_Reconciling_Adj(Lockbox, Credit_Date, Adj_Description, Adj_Amt, Created_By, Create_Date, Last_Modified_Date, Last_Modified_By) VALUES (@lockbox, @creditdate, @adj_desc, @adj_amt, @createdby, @createdate, @lastmodifieddate, @lastmodifiedby)" 
                SelectCommand="SELECT FMS_Reconciling_Adj.* FROM FMS_Reconciling_Adj" 
                ProviderName="<%$ ConnectionStrings:FMSConnectionString.ProviderName %>">
                <InsertParameters>
                    <asp:ControlParameter ControlID="txtbxLockbox" Name="lockbox" 
                        PropertyName="Text" />
                    <asp:ControlParameter ControlID="txtbxCreditDate" Name="creditdate" 
                        PropertyName="Text" />
                    <asp:Parameter Name="adj_desc" />
                    <asp:Parameter Name="adj_amt" />
                    <asp:Parameter Name="createdby" />
                    <asp:Parameter Name="createdate" DefaultValue="Now" />
                    <asp:Parameter Name="lastmodifieddate" DefaultValue="Now" />
                    <asp:Parameter Name="lastmodifiedby" />
                </InsertParameters>
            </asp:SqlDataSource>

Open in new window

0
Comment
Question by:imstac73
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:duttcom
Comment Utility
At first glance, it looks like your parameter

<asp:Parameter Name="adj_desc" /> is not right - you haven't given adj_desc a value anywhere.

You either need to make it a control parameter that refers to the Adj_DescriptionTextBox ID in the listview-

<asp:ControlParameter ControlID="Adj_DescriptionTextBox" Name="adj_desc" />

or you will need to use the name of the bound field-

<asp:Parameter Name="Adj_Description" />
0
 

Author Comment

by:imstac73
Comment Utility
Okay, I thought having the control bound in the formview handled that but I will update my parameter line in the sqldatasource code. Thanks.
0
 

Author Comment

by:imstac73
Comment Utility
I added this code to my sqlserver datasource insert command:
<asp:ControlParameter ControlID="Adj_DescriptionTextBox" Name="adj_desc" />

I get the following error:
Could not find control 'Adj_DescriptionTextBox' in ControlParameter 'adj_desc'.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
You have same name for this control in both Edit and Insert templates. What happens if you change the textbox name in edit template?

Also, you need to specify
PropertyName="Text"

in control parameter.
0
 

Author Comment

by:imstac73
Comment Utility
I added the PropertyName="Text" to the parameter attributes and changed the name of the textbox control in the edittimetemplate and I am still getting the error.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Does it work if you change the controlid to "fvInsertNewAdjusment$Adj_DescriptionTextBox"?
0
 

Author Comment

by:imstac73
Comment Utility
Thanks that worked!  Very strange; I've never had to put the actual form name in the parameters.  Appreciate your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now