Answered by:
Null Error Upon Insert

Question
-
User-723833757 posted
I cannot figure out why I am getting this null error on insert on my formview
<asp:FormView ID="fvWebsite" runat="server" DataKeyNames="CustomerID" DataSourceID="sqlWebsite" OnDataBound="fvWebsite_DataBound" OnItemDeleted="fvWebsite_ItemDeleted" OnItemInserted="fvWebsite_ItemInserted" OnItemUpdated="fvWebsite_ItemUpdated"> <EditItemTemplate> <div class="edit"> <div class="item"> <asp:Label ID="Label2" runat="server" Text="Edit Your Website Address:" SkinID="lbFormItemEdit" /> </div> <div class="input"> <asp:TextBox ID="tbWebsite" runat="server" Text='<%# Bind("WebsiteUrl") %>' MaxLength="128" /> <ajx:FilteredTextBoxExtender ID="fteWebsite" runat="server" TargetControlID="tbWebsite" SkinID="NoCode" /> <asp:RequiredFieldValidator ID="rfvWebsite" runat="server" ErrorMessage="RequiredFieldValidator" ValidationGroup="Website" ControlToValidate="tbWebsite" /> <asp:RegularExpressionValidator ID="revWebsite" runat="server" ControlToValidate="tbWebsite" ErrorMessage="RegularExpressionValidator" ValidationExpression="^((ht|f)tp(s?)\://w{3}\.|w{3}\.)[a-zA-Z0-9]{1,}\.(biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)$" ValidationGroup="Website" /> </div> <div class="button"> <asp:ImageButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" ValidationGroup="Website" SkinID="btnfvEdit" ImageUrl="~/App_Images/Buttons/bl/btnfvUpdate.gif" /> <asp:ImageButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" SkinID="btnfvCancel" ImageUrl="~/App_Images/Buttons/bl/btnfvCancel.gif" /> </div> </div> </EditItemTemplate> <InsertItemTemplate> <div class="edit"> <div class="item"> <asp:Label ID="Label2" runat="server" Text="Add Your Website Address:" SkinID="lbFormItem" /> </div> <div class="input"> <asp:TextBox ID="tbWebsite" runat="server" Text='<%# Bind("WebsiteUrl") %>' MaxLength="128" /> <ajx:DropShadowExtender ID="dseWebsite" runat="server" TargetControlID="tbWebsite" /> <ajx:FilteredTextBoxExtender ID="fteWebsite" runat="server" TargetControlID="tbWebsite" SkinID="NoCode" /> <asp:RequiredFieldValidator ID="rfvWebsite" runat="server" ErrorMessage="REQUIRED" ValidationGroup="Website" ControlToValidate="tbWebsite" /> <asp:RegularExpressionValidator ID="revWebsite" runat="server" ControlToValidate="tbWebsite" ErrorMessage="INVALID FORMAT" ValidationExpression="^((ht|f)tp(s?)\://w{3}\.|w{3}\.)[a-zA-Z0-9]{1,}\.(biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)$" ValidationGroup="Website" /> </div> <div class="button"> <asp:ImageButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" SkinID="btnfvInsert" ValidationGroup="Website" ImageUrl="~/App_Images/Buttons/bl/btnfvInsert.gif" /> <asp:ImageButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" SkinID="btnfvCancel" ImageUrl="~/App_Images/Buttons/bl/btnfvCancel.gif" /> </div> </div> </InsertItemTemplate> <ItemTemplate> <div class="new"> <div class="item"> <asp:Label ID="Label2" runat="server" Text="Website:" SkinID="lbFormItem" /> </div> <div class="input"> <asp:Label ID="WebsiteUrlLabel" runat="server" Text='<%# Bind("WebsiteUrl") %>' SkinID="lbFormData" /> </div> <div class="button"> <asp:ImageButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" SkinID="btnfvEdit" ImageUrl="~/App_Images/Buttons/bl/btnfvEdit.gif" /> <asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" SkinID="btnfvEdit" ImageUrl="~/App_Images/Buttons/bl/btnfvDelete.gif" /> </div> </div> </ItemTemplate> <EmptyDataTemplate> <div class="new"> <div class="item"> <asp:Label ID="Label2" runat="server" Text="Website:" SkinID="lbFormItem" /> </div> <div class="input"> <asp:Label ID="WebsiteUrlLabel" runat="server" Text="No Website Address Entered" SkinID="lbFormData" /> </div> <div class="button"> <asp:ImageButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="Add" SkinID="btnfvAdd" ImageUrl="~/App_Images/Buttons/bl/btnfvAdd.gif" /> </div> </div> </EmptyDataTemplate> </asp:FormView> <asp:SqlDataSource ID="sqlWebsite" runat="server" ConnectionString="<%$ ConnectionStrings:csSolutions %>" DeleteCommand="DELETE FROM [customer_website] WHERE [CustomerID] = @CustomerID" InsertCommand="INSERT INTO [customer_website] ([CustomerID], [WebsiteUrl], [LowerWebsiteUrl]) VALUES (@CustomerID, @WebsiteUrl, LOWER(@WebsiteUrl))" SelectCommand="SELECT [CustomerID], [WebsiteUrl] FROM [customer_website] WHERE ([CustomerID] = @CustomerID)" UpdateCommand="UPDATE [customer_website] SET [WebsiteUrl] = @WebsiteUrl, [LowerWebsiteUrl] = LOWER(@WebsiteUrl) WHERE [CustomerID] = @CustomerID"> <SelectParameters> <asp:ProfileParameter Name="CustomerID" PropertyName="Customers.CustomerID" Type="Int64" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="CustomerID" Type="Int64" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="WebsiteUrl" Type="String" /> <asp:Parameter Name="CustomerID" Type="Int64" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="CustomerID" Type="Int64" /> <asp:Parameter Name="WebsiteUrl" Type="String" /> </InsertParameters> </asp:SqlDataSource>
It says I cannot insert a null value into the CustomerID column, I know that, but why would it be null, it should have a value from the ProfileParameter. All of the other formviews work and they are set up the same way. Can anyone see anything I can't?Monday, January 24, 2011 8:06 PM
Answers
-
User1288251396 posted
Hello, again, Bobby!
I see you using a ProfileParameter in your <SelectParameters>, but not in your <InsertParameters>. That could do it.
If that isn't it, I'd start by putting a breakpoint in my sqlWebsite.Selecting handler and look at the value actually in the parameter.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 24, 2011 9:02 PM
All replies
-
User1288251396 posted
Hello, again, Bobby!
I see you using a ProfileParameter in your <SelectParameters>, but not in your <InsertParameters>. That could do it.
If that isn't it, I'd start by putting a breakpoint in my sqlWebsite.Selecting handler and look at the value actually in the parameter.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, January 24, 2011 9:02 PM -
User-723833757 posted
Ill try that, I didn't think to do that since I didn't see it in any of the other datasources. I thought once the select statement was run, the data was there and available for the insert, and update, but this fixed it thanks
Tuesday, January 25, 2011 9:39 AM