Solved

Getting error on ItemInserting event on Formview

Posted on 2014-04-22
7
251 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

10 Experts available now in Live!

Get 1:1 Help Now