FormView Update fails with InvalidCastException

G

Guest

Hi,

I have a FormView control on a page which is bound to a SQLDataSource table.
Everything works fine except for the "Update". I get an
InvalidCastException. The problem only seems to surface when I have a
'datetime' column in the table. I tested this with a very simple sample
table. As long as there is no datetime column either in the table or on the
form, all are peachy. Here is the code, in case somebody can figure it out.
I would really appreciate a post if you know a solution.
 
G

Guest

Sorry, I forgot to paste the code. Here it is.

<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataKeyNames="PKId"
DataSourceID="SqlDataSource1">
<PagerSettings Mode="NumericFirstLast" />
<EditItemTemplate>
PKId:
<asp:Label ID="PKIdLabel1" runat="server" Text='<%# Eval("PKId")
%>'></asp:Label><br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%#
Bind("Description") %>'>
</asp:TextBox><br />
ItemNum:
<asp:TextBox ID="ItemNumTextBox" runat="server" Text='<%#
Bind("ItemNum") %>'>
</asp:TextBox><br />
Modified:
<asp:TextBox ID="ModifiedTextBox" runat="server" Text='<%#
Bind("Modified") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%#
Bind("Description") %>'>
</asp:TextBox><br />
ItemNum:
<asp:TextBox ID="ItemNumTextBox" runat="server" Text='<%#
Bind("ItemNum") %>'>
</asp:TextBox><br />
Modified:
<asp:TextBox ID="ModifiedTextBox" runat="server" Text='<%#
Bind("Modified") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
PKId:
<asp:Label ID="PKIdLabel" runat="server" Text='<%# Eval("PKId")
%>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name")
%>'></asp:Label><br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Bind("Description") %>'>
</asp:Label><br />
ItemNum:
<asp:Label ID="ItemNumLabel" runat="server" Text='<%# Bind("ItemNum")
%>'></asp:Label><br />
Modified:
<asp:Label ID="ModifiedLabel" runat="server" Text='<%# Bind("Modified")
%>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server"
CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DataNozzleOrgConnectionString %>"
DeleteCommand="aaTableDelete" DeleteCommandType="StoredProcedure"
InsertCommand="aaTableInsert"
InsertCommandType="StoredProcedure" SelectCommand="aaTableSelectAll"
SelectCommandType="StoredProcedure"
UpdateCommand="aaTableUpdate" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:parameter Name="PKId" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="FormView1" Name="PKId"
PropertyName="SelectedValue"
Type="Decimal" />
<asp:ControlParameter ControlID="FormView1" Name="Name"
PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="FormView1" Name="Description"
PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="FormView1" Name="ItemNum"
PropertyName="SelectedValue"
Type="Decimal" />
<asp:ControlParameter ControlID="FormView1" Name="Modified"
PropertyName="SelectedValue"
Type="DateTime" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter ControlID="FormView1" Direction="InputOutput"
Name="PKId" PropertyName="SelectedValue"
Type="Decimal" />
<asp:ControlParameter ControlID="FormView1" Name="Name"
PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="FormView1" Name="Description"
PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="FormView1" Name="ItemNum"
PropertyName="SelectedValue"
Type="Decimal" />
<asp:parameter Direction="ReturnValue" Name="RETURN_VALUE" Type="Int32"
/>
<asp:ControlParameter ControlID="FormView1" Name="Modified"
PropertyName="SelectedValue"
Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top