?
Solved

Getting error on ItemInserting event on Formview

Posted on 2014-04-22
7
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:duttcom
ID: 40016410
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
ID: 40017505
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
ID: 40017514
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
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40020019
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
ID: 40020068
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 2000 total points
ID: 40020083
Does it work if you change the controlid to "fvInsertNewAdjusment$Adj_DescriptionTextBox"?
0
 

Author Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

800 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