Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Dear all ,
I am working on gridview  and there are two dropdownlist in gridview edit template with respective sqldatasource.
what i want to do is update the record when i will click on update button which is generated through gridview
but it is throwing error :
=====
Cannot insert the value NULL into column 'CompanyID', table 'RealValue.dbo.tbl_BikePrcInfo'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
 ======
please help me

Thanks in adv.......
Posted

1 solution

This error is because we are not getting the DorpdownList SelectedValue, when we click on the Update button. It returns NULL to us. That's why it shows below error.

Cannot insert the value NULL into column 'CompanyID', table 'RealValue.dbo.tbl_BikePrcInfo'; column does not allow nulls. UPDATE fails.

Please debug your code and check the values.
 
Share this answer
 
Comments
Maddy_1008 23-Jun-11 5:18am    
Thanks for reply 2irfanshaikh1

but when i set SelectedValue property and click on Edit it throw error like this.
what should i do?

'DrpDwnLstVwModel' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
[no name] 23-Jun-11 5:23am    
please provide line of codes. i can help you with the issue.
Maddy_1008 23-Jun-11 5:53am    
<asp:TemplateField HeaderText="CompanyID" SortExpression="CompanyID">
<edititemtemplate>
<asp:DropDownList ID="DrpDwnLstGRdVwCmpy" runat="server" AutoPostBack="True" DataSourceID="SqlDtSrcGrdVwCmpy"
DataTextField="CompanyName" DataValueField="CompanyID" AppendDataBoundItems="True">

<asp:SqlDataSource ID="SqlDtSrcGrdVwCmpy" runat="server" ConnectionString="<%$ ConnectionStrings:RealValueConnectionString %>"
SelectCommand="SELECT [CompanyID], [CompanyName] FROM [tbl_BikeCompanyMaster]">


<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("CompanyName") %>'>




UpdateCommand="UPDATE [tbl_BikePrcInfo] SET [CompanyID] = @CompanyID, [ModelID] = @ModelID, [Year1] = @Year1, [Year2] = @Year2, [Year3] = @Year3, [Year4] = @Year4, [Year5] = @Year5 WHERE [BikePriceID] = @BikePriceID">
<deleteparameters>
<asp:Parameter Name="BikePriceID" Type="Int32" />

<updateparameters>
<asp:Parameter Name="CompanyID" Type="Int32" />
<asp:Parameter Name="ModelID" Type="Int32" />
<asp:Parameter Name="Year1" Type="Int32" />
<asp:Parameter Name="Year2" Type="Int32" />
<asp:Parameter Name="Year3" Type="Int32" />
<asp:Parameter Name="Year4" Type="Int32" />
<asp:Parameter Name="Year5" Type="Int32" />
<asp:Parameter Name="BikePriceID" Type="Int32" />


this is my part of code.
[no name] 23-Jun-11 7:35am    
please provide the update button click event code..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900