This should be simple, but...

  1. #1

    This should be simple, but...

    I would love to use this in future projects so I'm testing out just a little of the CRUD functions with a simple SQL Server database. I'm attempting to insert a new record from a formpanel, which would seem fairly common. However, the table I'm updating has a auto-generated key field called "REC_NUM". I've left this field out of the Model, Store and Insert Parameters, but I did use it in the IDProperty of the Model. I continue to get the following error:

    System.Exception: Key value is not defined for inserted record

    No, I have not defined it. Should I have to? Perhaps my insert Method syntax is incorrect? I couldn't really find any examples of an insert statement from a form.

    Please give this simple program a quick look and let me know where changes are required.

    Thanks, RJ
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="edsradd.aspx.cs" Inherits="edsradd" %>
    
    <!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>
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EDSRConnectionString %>"
        InsertCommand="INSERT INTO DAILY_STATUS_REPORT_TABLE 
                                   (CONSULTANT_NAME,
                                    REPORT_DATE,
                                    CLIENT_NAME, 
                                    ACTIVITY_CODE, 
                                    PROJECT_DESC, 
                                    DETAIL_DESC, 
                                    RESULT_CODE, 
                                    BILL_TIME_NUM, 
                                    NONBILL_TIME_NUM, 
                                    BILL_TYPE_CODE,
                                    RATE_AMT,
                                    BILL_AMT,
                                    COMPLETED,
                                    ) 
                                VALUES 
                                     (@CONSULTANT_NAME,
                                    @REPORT_DATE,
                                    @CLIENT_NAME, 
                                    @ACTIVITY_CODE, 
                                    @PROJECT_DESC, 
                                    @DETAIL_DESC, 
                                    @RESULT_CODE, 
                                    @BILL_TIME_NUM, 
                                    @NONBILL_TIME_NUM, 
                                    @BILL_TYPE_CODE,
                                    @RATE_AMT,
                                    @BILL_AMT,
                                    @COMPLETED
                                    ) ;"
        >
        <InsertParameters>
                <asp:Parameter Name="CONSULTANT_NAME" />
                <asp:Parameter Name="REPORT_DATE" />
                <asp:Parameter Name="CLIENT_NAME" />
                <asp:Parameter Name="ACTIVITY_CODE" />
                <asp:Parameter Name="PROJECT_DESC" />
                <asp:Parameter Name="DETAIL_DESC" />
                <asp:Parameter Name="RESULT_CODE" />
                <asp:Parameter Name="BILL_TIME_NUM" />
                <asp:Parameter Name="NONBILL_TIME_NUM" />
                <asp:Parameter Name="BILL_TYPE_CODE" />
                <asp:Parameter Name="RATE_AMT" />
                <asp:Parameter Name="BILL_AMT" />
                <asp:Parameter Name="COMPLETED" />
            </InsertParameters>
        </asp:SqlDataSource>
        <ext:Store
            ID="Store1" 
                runat="server" 
                DataSourceID="SqlDataSource1">
                <Model>
                    <ext:Model ID="Model1" runat="server" IDProperty="REC_NUM" Name="edsrModel">
                        <Fields>
                        <ext:ModelField Name="CONSULTANT_NAME" Mapping="NCONSULTANT_NAME" />
                        <ext:ModelField Name="CLIENT_NAME" Mapping="CLIENT_NAME_ADD" />
                        <ext:ModelField Name="ACTIVITY_CODE" Mapping="ACTIVITY_CODE_ADD" />
                        <ext:ModelField Name="BILL_TIME_NUM" Mapping="NBILL_TIME_NUM" />
                        <ext:ModelField Name="REPORT_DATE" Type="Date" Mapping="NREPORT_DATE" />
                        <ext:ModelField Name="NONBILL_TIME_NUM" Mapping="NNONBILL_TIME_NUM" />
                        <ext:ModelField Name="RESULT_CODE" Mapping="NRESULT_CODE" />
                        <ext:ModelField Name="COMPLETED" Mapping="NCOMPLETED" />
                        <ext:ModelField Name="PROJECT_DESC" Mapping="NPROJECT_DESC" />
                        <ext:ModelField Name="DETAIL_DESC" Mapping="NDETAIL_DESC" />
                        <ext:ModelField Name="BILL_TYPE_CODE" Mapping="NBILL_TYPE_CODE" />
                        <ext:ModelField Name="RATE_AMT" Mapping="NRATE_AMT" />
                        <ext:ModelField Name="BILL_AMT" Mapping="NBILL_AMT" />
                        </Fields>
                    </ext:Model>
                </Model>
        </ext:Store>
        <form id="form1" runat="server">
        <div>
            <ext:FormPanel ID="addform" runat="server" BodyStyle="padding:15px">
            <Items>
                <ext:Container ID="Container5" runat="server" Layout="Column" Height="150">
                    <Items>
                        <ext:Container ID="Container6" runat="server" Layout="AnchorLayout" ColumnWidth=".3">
                            <Items>
                                <ext:ComboBox ID="ComboBox11" runat="server" FieldLabel="Consultant" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NCONSULTANT_NAME" TypeAhead="true" QueryMode="Local"
                                    ForceSelection="true" TriggerAction="All" SelectOnFocus="true" DisplayField="CONSULTANT_NAME"
                                    ValueField="CONSULTANT_NAME" EmptyText="Select..." ValueNotFoundText="Loading...">
                                    <Items>
                                        <ext:ListItem Text="RJ Mallette" Value="RJ Mallette" />
                                        <ext:ListItem Text="Ron Watts" Value="Ron Watts" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="Ron Watts" />
                                    </SelectedItems>
                                </ext:ComboBox>
                                <ext:DateField ID="DateField2" runat="server" FieldLabel="Date" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NREPORT_DATE" />
                                <ext:ComboBox ID="ComboBox6" runat="server" FieldLabel="Client" AnchorHorizontal="95%"
                                    LabelAlign="Left" TypeAhead="true" QueryMode="Remote" ForceSelection="true" TriggerAction="All"
                                    SelectOnFocus="true" DisplayField="CLIENT_NAME" ValueField="CLIENT_NAME" EmptyText="Select..."
                                    ValueNotFoundText="Loading..." Name="CLIENT_NAME_ADD">
                                    <Items>
                                        <ext:ListItem Text="ALBERTA" Value="ALBERTA" />
                                        <ext:ListItem Text="COLA" Value="COLA" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="COLA" />
                                    </SelectedItems>
                                </ext:ComboBox>
                                <ext:ComboBox ID="ComboBox7" runat="server" FieldLabel="Activity" AnchorHorizontal="95%"
                                    LabelAlign="Left" TypeAhead="true" QueryMode="Local" ForceSelection="false" TriggerAction="All"
                                    DisplayField="ACTIVITY_CODE" ValueField="ACTIVITY_CODE" Name="ACTIVITY_CODE_ADD">
                                    <Items>
                                        <ext:ListItem Text="PROGRAMMING" Value="PROGRAMMING" />
                                        <ext:ListItem Text="REPORTING" Value="REPORTING" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="REPORTING" />
                                    </SelectedItems>
                                </ext:ComboBox>
                                <ext:ComboBox ID="ComboBox8" runat="server" FieldLabel="Result" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NRESULT_CODE">
                                    <Items>
                                        <ext:ListItem Text="Win" Value="WIN" />
                                        <ext:ListItem Text="Lose" Value="LOSE" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="WIN" />
                                    </SelectedItems>
                                </ext:ComboBox>
                                <ext:ComboBox ID="ComboBox9" runat="server" FieldLabel="Complete" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NCOMPLETED">
                                    <Items>
                                        <ext:ListItem Text="Yes" Value="YES" />
                                        <ext:ListItem Text="No" Value="NO" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="YES" />
                                    </SelectedItems>
                                </ext:ComboBox>
                            </Items>
                        </ext:Container>
                        <ext:Container ID="Container7" runat="server" Layout="AnchorLayout" ColumnWidth=".4">
                            <Items>
                                <ext:TextArea ID="TextArea3" runat="server" FieldLabel="Description" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NPROJECT_DESC" />
                                <ext:TextArea ID="TextArea4" runat="server" FieldLabel="Notes" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NDETAIL_DESC" />
                            </Items>
                        </ext:Container>
                        <ext:Container ID="Container8" runat="server" Layout="AnchorLayout" ColumnWidth=".3">
                            <Items>
                                <ext:NumberField ID="NumberField5" runat="server" FieldLabel="Billable" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NBILL_TIME_NUM" />
                                <ext:NumberField ID="NumberField6" runat="server" FieldLabel="Non-Billiable" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NNONBILL_TIME_NUM" />
                                <ext:ComboBox ID="ComboBox10" runat="server" FieldLabel="Bill Type" AnchorHorizontal="95%"
                                    LabelAlign="Left" ForceSelection="false" Name="NBILL_TYPE_CODE">
                                    <Items>
                                        <ext:ListItem Text="HOURLY" Value="HOURLY" />
                                        <ext:ListItem Text="FLAT" Value="FLAT" />
                                        <ext:ListItem Text="NOBILL" Value="NOBILL" />
                                    </Items>
                                </ext:ComboBox>
                                <ext:NumberField ID="NumberField7" runat="server" FieldLabel="Rate" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NRATE_AMT" />
                                <ext:NumberField ID="NumberField8" runat="server" FieldLabel="Bill Amount" AnchorHorizontal="95%"
                                    LabelAlign="Left" Name="NBILL_AMT" />
                                <ext:DateField ID="Panel4date" runat="server" Hidden="true" />
                                <ext:DateField ID="Panel4endDt" runat="server" Hidden="true" />
                                <ext:Label ID="Panel4title" runat="server" Hidden="true" />
                            </Items>
                        </ext:Container>
                    </Items>
                </ext:Container>
            </Items>
            <Buttons>
                <ext:Button ID="Button5" runat="server" Text="Insert">
                    <Listeners>
                        <Click Handler="#{Store1}.insert(0, new edsrModel(#{addform}.getForm().getFieldValues()));" />
                    </Listeners>
                    </ext:Button>
                <ext:Button ID="Savebtn" runat="server" Text="Save">
                    <Listeners>
                        <Click Handler="#{Store1}.sync();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="Button6" runat="server" Text="Cancel" />
                <ext:Button ID="Button7" runat="server" Text="Click Me" Icon="Lightning">
                    <Listeners>
                        <Click Handler="
                        ext.direct.GetTimeStamp({
                            success: function (result) {
                                Ext.Msg.alert('Server Time', result);
                            }
                        });" />
                    </Listeners>
                </ext:Button>
                </Buttons>
            </ext:FormPanel>
        
        </div>
        </form>
    </body>
    </html>
    Last edited by randallm; Nov 27, 2012 at 2:02 PM.
  2. #2

    Any suggestions at all?

    So can anyone see anything at all that is blatantly wrong? Any guesses?
  3. #3

    Backend only

    Should I just do the Insert using a procedure on the backend instead of trying to use this method? Seems that I can't get the right parameters to avoid this error. Has anyone been able to insert a record with an Identity column with auto-increment?
  4. #4

    Any Ideas?

    Has anyone received this error with an auto-generated identity field?

    "System.Exception: Key value is not defined for inserted record"

    I'm hoping the code tags make it a little more readable.

    Any help is appreciated as I would really like to make this work.

    Thanks, RJ

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="edsradd.aspx.cs" Inherits="edsradd" %>
    
    <!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>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EDSRConnectionString %>"
    InsertCommand="INSERT INTO DAILY_STATUS_REPORT_TABLE 
    (CONSULTANT_NAME,
    REPORT_DATE,
    CLIENT_NAME, 
    ACTIVITY_CODE, 
    PROJECT_DESC, 
    DETAIL_DESC, 
    RESULT_CODE, 
    BILL_TIME_NUM, 
    NONBILL_TIME_NUM, 
    BILL_TYPE_CODE,
    RATE_AMT,
    BILL_AMT,
    COMPLETED,
    ) 
    VALUES 
    (@CONSULTANT_NAME,
    @REPORT_DATE,
    @CLIENT_NAME, 
    @ACTIVITY_CODE, 
    @PROJECT_DESC, 
    @DETAIL_DESC, 
    @RESULT_CODE, 
    @BILL_TIME_NUM, 
    @NONBILL_TIME_NUM, 
    @BILL_TYPE_CODE,
    @RATE_AMT,
    @BILL_AMT,
    @COMPLETED
    ) ;"
    >
    <InsertParameters>
    <asp:Parameter Name="CONSULTANT_NAME" />
    <asp:Parameter Name="REPORT_DATE" />
    <asp:Parameter Name="CLIENT_NAME" />
    <asp:Parameter Name="ACTIVITY_CODE" />
    <asp:Parameter Name="PROJECT_DESC" />
    <asp:Parameter Name="DETAIL_DESC" />
    <asp:Parameter Name="RESULT_CODE" />
    <asp:Parameter Name="BILL_TIME_NUM" />
    <asp:Parameter Name="NONBILL_TIME_NUM" />
    <asp:Parameter Name="BILL_TYPE_CODE" />
    <asp:Parameter Name="RATE_AMT" />
    <asp:Parameter Name="BILL_AMT" />
    <asp:Parameter Name="COMPLETED" />
    </InsertParameters>
    </asp:SqlDataSource>
    <ext:Store
    ID="Store1" 
    runat="server" 
    DataSourceID="SqlDataSource1">
    <Model>
    <ext:Model ID="Model1" runat="server" IDProperty="REC_NUM" Name="edsrModel">
    <Fields>
    <ext:ModelField Name="CONSULTANT_NAME" Mapping="NCONSULTANT_NAME" />
    <ext:ModelField Name="CLIENT_NAME" Mapping="CLIENT_NAME_ADD" />
    <ext:ModelField Name="ACTIVITY_CODE" Mapping="ACTIVITY_CODE_ADD" />
    <ext:ModelField Name="BILL_TIME_NUM" Mapping="NBILL_TIME_NUM" />
    <ext:ModelField Name="REPORT_DATE" Type="Date" Mapping="NREPORT_DATE" />
    <ext:ModelField Name="NONBILL_TIME_NUM" Mapping="NNONBILL_TIME_NUM" />
    <ext:ModelField Name="RESULT_CODE" Mapping="NRESULT_CODE" />
    <ext:ModelField Name="COMPLETED" Mapping="NCOMPLETED" />
    <ext:ModelField Name="PROJECT_DESC" Mapping="NPROJECT_DESC" />
    <ext:ModelField Name="DETAIL_DESC" Mapping="NDETAIL_DESC" />
    <ext:ModelField Name="BILL_TYPE_CODE" Mapping="NBILL_TYPE_CODE" />
    <ext:ModelField Name="RATE_AMT" Mapping="NRATE_AMT" />
    <ext:ModelField Name="BILL_AMT" Mapping="NBILL_AMT" />
    </Fields>
    </ext:Model>
    </Model>
    </ext:Store>
    <form id="form1" runat="server">
    <div>
    <ext:FormPanel ID="addform" runat="server" BodyStyle="padding:15px">
    <Items>
    <ext:Container ID="Container5" runat="server" Layout="Column" Height="150">
    <Items>
    <ext:Container ID="Container6" runat="server" Layout="AnchorLayout" ColumnWidth=".3">
    <Items>
    <ext:ComboBox ID="ComboBox11" runat="server" FieldLabel="Consultant" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NCONSULTANT_NAME" TypeAhead="true" QueryMode="Local"
    ForceSelection="true" TriggerAction="All" SelectOnFocus="true" DisplayField="CONSULTANT_NAME"
    ValueField="CONSULTANT_NAME" EmptyText="Select..." ValueNotFoundText="Loading...">
    <Items>
    <ext:ListItem Text="RJ Mallette" Value="RJ Mallette" />
    <ext:ListItem Text="Ron Watts" Value="Ron Watts" />
    </Items>
    <SelectedItems>
    <ext:ListItem Value="Ron Watts" />
    </SelectedItems>
    </ext:ComboBox>
    <ext:DateField ID="DateField2" runat="server" FieldLabel="Date" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NREPORT_DATE" />
    <ext:ComboBox ID="ComboBox6" runat="server" FieldLabel="Client" AnchorHorizontal="95%"
    LabelAlign="Left" TypeAhead="true" QueryMode="Remote" ForceSelection="true" TriggerAction="All"
    SelectOnFocus="true" DisplayField="CLIENT_NAME" ValueField="CLIENT_NAME" EmptyText="Select..."
    ValueNotFoundText="Loading..." Name="CLIENT_NAME_ADD">
    <Items>
    <ext:ListItem Text="ALBERTA" Value="ALBERTA" />
    <ext:ListItem Text="COLA" Value="COLA" />
    </Items>
    <SelectedItems>
    <ext:ListItem Value="COLA" />
    </SelectedItems>
    </ext:ComboBox>
    <ext:ComboBox ID="ComboBox7" runat="server" FieldLabel="Activity" AnchorHorizontal="95%"
    LabelAlign="Left" TypeAhead="true" QueryMode="Local" ForceSelection="false" TriggerAction="All"
    DisplayField="ACTIVITY_CODE" ValueField="ACTIVITY_CODE" Name="ACTIVITY_CODE_ADD">
    <Items>
    <ext:ListItem Text="PROGRAMMING" Value="PROGRAMMING" />
    <ext:ListItem Text="REPORTING" Value="REPORTING" />
    </Items>
    <SelectedItems>
    <ext:ListItem Value="REPORTING" />
    </SelectedItems>
    </ext:ComboBox>
    <ext:ComboBox ID="ComboBox8" runat="server" FieldLabel="Result" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NRESULT_CODE">
    <Items>
    <ext:ListItem Text="Win" Value="WIN" />
    <ext:ListItem Text="Lose" Value="LOSE" />
    </Items>
    <SelectedItems>
    <ext:ListItem Value="WIN" />
    </SelectedItems>
    </ext:ComboBox>
    <ext:ComboBox ID="ComboBox9" runat="server" FieldLabel="Complete" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NCOMPLETED">
    <Items>
    <ext:ListItem Text="Yes" Value="YES" />
    <ext:ListItem Text="No" Value="NO" />
    </Items>
    <SelectedItems>
    <ext:ListItem Value="YES" />
    </SelectedItems>
    </ext:ComboBox>
    </Items>
    </ext:Container>
    <ext:Container ID="Container7" runat="server" Layout="AnchorLayout" ColumnWidth=".4">
    <Items>
    <ext:TextArea ID="TextArea3" runat="server" FieldLabel="Description" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NPROJECT_DESC" />
    <ext:TextArea ID="TextArea4" runat="server" FieldLabel="Notes" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NDETAIL_DESC" />
    </Items>
    </ext:Container>
    <ext:Container ID="Container8" runat="server" Layout="AnchorLayout" ColumnWidth=".3">
    <Items>
    <ext:NumberField ID="NumberField5" runat="server" FieldLabel="Billable" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NBILL_TIME_NUM" />
    <ext:NumberField ID="NumberField6" runat="server" FieldLabel="Non-Billiable" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NNONBILL_TIME_NUM" />
    <ext:ComboBox ID="ComboBox10" runat="server" FieldLabel="Bill Type" AnchorHorizontal="95%"
    LabelAlign="Left" ForceSelection="false" Name="NBILL_TYPE_CODE">
    <Items>
    <ext:ListItem Text="HOURLY" Value="HOURLY" />
    <ext:ListItem Text="FLAT" Value="FLAT" />
    <ext:ListItem Text="NOBILL" Value="NOBILL" />
    </Items>
    </ext:ComboBox>
    <ext:NumberField ID="NumberField7" runat="server" FieldLabel="Rate" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NRATE_AMT" />
    <ext:NumberField ID="NumberField8" runat="server" FieldLabel="Bill Amount" AnchorHorizontal="95%"
    LabelAlign="Left" Name="NBILL_AMT" />
    <ext:DateField ID="Panel4date" runat="server" Hidden="true" />
    <ext:DateField ID="Panel4endDt" runat="server" Hidden="true" />
    <ext:Label ID="Panel4title" runat="server" Hidden="true" />
    </Items>
    </ext:Container>
    </Items>
    </ext:Container>
    </Items>
    <Buttons>
    <ext:Button ID="Button5" runat="server" Text="Insert">
    <Listeners>
    <Click Handler="#{Store1}.insert(0, new edsrModel(#{addform}.getForm().getFieldValues())); " />
    </Listeners>
    </ext:Button>
    <ext:Button ID="Savebtn" runat="server" Text="Save">
    <Listeners>
    <Click Handler="#{Store1}.sync();" />
    </Listeners>
    </ext:Button>
    <ext:Button ID="Button6" runat="server" Text="Cancel" />
    <ext:Button ID="Button7" runat="server" Text="Click Me" Icon="Lightning">
    <Listeners>
    <Click Handler="
    ext.direct.GetTimeStamp({
    success: function (result) {
    Ext.Msg.alert('Server Time', result);
    }
    });" />
    </Listeners>
    </ext:Button>
    </Buttons>
    </ext:FormPanel>
    
    </div>
    </form>
    </body>
    </html>
  5. #5

    Moving On

    I guess since no one else has had this issue, I'll just do the insert on the backend and move forward.

Similar Threads

  1. [CLOSED] Simple or not ?
    By sisa in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 20, 2011, 7:59 AM
  2. This could possibly be a very simple problem.
    By RowanRishi in forum 1.x Help
    Replies: 2
    Last Post: Jul 19, 2011, 11:03 PM
  3. Its simple but Need help
    By kutbinahar in forum 1.x Help
    Replies: 0
    Last Post: Mar 05, 2011, 8:00 PM
  4. Simple panel with shadow?
    By reverseblade in forum 1.x Help
    Replies: 2
    Last Post: Apr 07, 2010, 12:38 AM
  5. [CLOSED] Simple Portal Example
    By mxp in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Nov 02, 2009, 5:21 PM

Posting Permissions