This is a migrated thread and some comments may be shown as answers.

RadGrid and ComboBox Insert

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Griffin
Top achievements
Rank 1
Scott Griffin asked on 13 Mar 2009, 02:33 PM
Can someone please help me with this?

Here is my error
 

Server Error in '/new broker' Application.

Cannot insert the value NULL into column 'BusinessTypeID', table 'ASPNETDB.dbo.ProducerBusinessType'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'BusinessTypeID', table 'ASPNETDB.dbo.ProducerBusinessType'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): Cannot insert the value NULL into column 'BusinessTypeID', table 'ASPNETDB.dbo.ProducerBusinessType'; column does not allow nulls. INSERT fails.
The statement has been terminated.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1950890
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846875
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +204
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +175
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +227
   System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +86
   Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem, Boolean suppressRebind) +281
   Telerik.Web.UI.GridTableView.PerformInsert(GridEditableItem editedItem) +41
   Telerik.Web.UI.GridTableView.PerformInsert() +65
   Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +5486
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +61
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +165
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +111
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565



Here is my code

 

<telerik:RadGrid ID="rgBizTypePercent" runat="server" Skin="Vista"

 

 

AutoGenerateColumns="False" DataSourceID="sdsBizTypePercentages"

 

 

AllowAutomaticInserts="true"

 

 

GridLines="None">

 

 

 

<HeaderContextMenu>

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

</HeaderContextMenu>

 

 

<MasterTableView EditMode="InPlace" DataKeyNames="ID"

 

 

CommandItemDisplay="Top" DataSourceID="sdsBizTypePercentages">

 

 

 

<Columns>

 

 

<telerik:GridEditCommandColumn ButtonType="ImageButton" Display="true"

 

 

Visible="true">

 

 

 

</telerik:GridEditCommandColumn>

 

 

<telerik:GridDropDownColumn DataSourceID="sdsBizType"

 

 

HeaderText="Business Type" ListTextField="Description"

 

 

ListValueField="BusinessTypeID" DataType="System.Int32"

 

 

UniqueName="BusinessTypeID">

 

 

</telerik:GridDropDownColumn>

 

 

<telerik:GridDropDownColumn DataSourceID="sdsPercent"

 

 

HeaderText="Business Percent" ListTextField="perc"

 

 

ListValueField="id" DataType="System.Int32"

 

 

UniqueName="Amount">

 

 

</telerik:GridDropDownColumn>

 

 

</Columns>

 

 

<EditFormSettings>

 

 

<EditColumn UniqueName="EditCommandColumn1">

 

 

</EditColumn>

 

 

</EditFormSettings>

 

 

</MasterTableView>

 

 

<FilterMenu>

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

</FilterMenu>

 

 

</telerik:RadGrid>

 

 

<asp:SqlDataSource ID="sdsBizTypePercentages" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:BROKERConnectionString %>"

 

 

SelectCommand="SELECT * FROM [ProducerBusinessType]"

 

 

DeleteCommand="DELETE FROM [ProducerBusinessType] WHERE [ProducerID] = @ProducerID AND [BusinessTypeID] = @BusinessTypeID"

 

 

InsertCommand="INSERT INTO [ProducerBusinessType] ([ProducerID], [BusinessTypeID], [Amount]) VALUES (@ProducerID, @BusinessTypeID, @Amount)"

 

 

UpdateCommand="UPDATE [ProducerBusinessType] SET [ID] = @ID, [Amount] = @Amount WHERE [ProducerID] = @ProducerID AND [BusinessTypeID] = @BusinessTypeID">

 

 

<InsertParameters>

 

 

<asp:SessionParameter Name="ProducerID" DefaultValue="100000" SessionField="ProducerID" Type="Int32" />

 

<%

--<asp:Parameter Name="ProducerID" Type="Int32" />--%>

 

 

<asp:FormParameter FormField="BusinessTypeID" Name="BusinessTypeID" Type="Int32" />

 

 

<asp:FormParameter FormField="Amount" Name="Amount" Type="Int32" />

 

 

 

</InsertParameters>

 

 

</asp:SqlDataSource>

 

 

<asp:SqlDataSource ID="sdsPercent" runat="server"

 

 

ConnectionString="<%$ ConnectionStrings:BROKERConnectionString %>"

 

 

SelectCommand="SELECT * FROM [LookupPercent]"></asp:SqlDataSource>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 16 Mar 2009, 03:06 PM
Hello Scott Griffin,

You should try setting the DataField property of the GridDropDownColumn. Going by your code, it should be:

                    <telerik:GridDropDownColumn DataField="BusinessTypeID" ....> 
                    </telerik:GridDropDownColumn> 


Best Regards,
Tsvetoslav
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Scott Griffin
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or