cannot insert null

2 posts, 0 answers
  1. Andreas Lohr
    Andreas Lohr avatar
    29 posts
    Member since:
    Aug 2009

    Posted 30 Nov 2012 Link to this post

    hi,
    I just try to setup a basic scenario with RadGrid using CRUD.
    So far select and delete works, but update and insert fails. I cannot see, whats going wrong.
    Here is my table definition:
    CREATE TABLE [dbo].[Projects] (
        [ProjectId]      INT              IDENTITY (1, 1) NOT NULL,
        [Project]        NVARCHAR (MAX)   NOT NULL,
        [OrganizationId] UNIQUEIDENTIFIER NOT NULL,
        [Created]        DATETIME         DEFAULT (getdate()) NULL,
        [Updated]        DATETIME         DEFAULT (getdate()) NULL,
        PRIMARY KEY CLUSTERED ([ProjectId] ASC)
    );
    The updated column has a trigger. Hope that is not the problem.
    The SqlDataSource is:
    <asp:SqlDataSource ID="SqlDataSourceProjects" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" DeleteCommand="DELETE FROM Projects WHERE (ProjectId = @ProjectId)" InsertCommand="INSERT INTO Projects(Project, OrganizationId) VALUES (@Project, @OrganizationId)" SelectCommand="SELECT Projects.* FROM Projects WHERE (OrganizationId = @OrganizationId)" UpdateCommand="UPDATE Projects SET Project = @Projects WHERE (OrganizationId = @OrganizationId)">
            <DeleteParameters>
                <asp:Parameter Name="ProjectId" DbType="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Project" DbType="String" />
                <asp:SessionParameter Name="OrganizationId" SessionField="OrganizationId" DbType="Guid" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter Name="OrganizationId" SessionField="OrganizationId" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Projects" DbType="String" />
                <asp:SessionParameter Name="OrganizationId" SessionField="OrganizationId" DbType="Guid" />
            </UpdateParameters>
        </asp:SqlDataSource>
    and the radGrid is:
    <telerik:RadGrid ID="RadGridProjects" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" CellSpacing="0" Culture="de-DE" DataSourceID="SqlDataSourceProjects" GridLines="None" Skin="Metro">
    <MasterTableView DataKeyNames="ProjectId" DataSourceID="SqlDataSourceProjects" CommandItemDisplay="TopAndBottom">
    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
     
    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
    <HeaderStyle Width="20px"></HeaderStyle>
    </RowIndicatorColumn>
     
    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
    <HeaderStyle Width="20px"></HeaderStyle>
    </ExpandCollapseColumn>
     
        <Columns>
            <telerik:GridBoundColumn DataField="ProjectId" DataType="System.Int32" FilterControlAltText="Filter ProjectId column" HeaderText="ProjectId" ReadOnly="True" SortExpression="ProjectId" UniqueName="ProjectId">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Project" FilterControlAltText="Filter Project column" HeaderText="Project" SortExpression="Project" UniqueName="Project">
            </telerik:GridBoundColumn>
        </Columns>
     
    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
    </MasterTableView>
     
    <FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
    It would be really nice, if some pros can tell me, what is wrong.
    Thanks in advance!
    Andreas

  2. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 05 Dec 2012 Link to this post

    Hi Andreas,

    I suggest you check out the following example. Note that you have to insert/edit the OrganizationId because does not accept null and will throw an exception.

    Greetings,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top