473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

FormView Update fails with InvalidCastException

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.
--
BabuMan

Jul 9 '06 #1
1 1807
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>

--
BabuMan
"BabuMan" wrote:
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.
--
BabuMan
Jul 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
3
by: Jurgen Appelo | last post by:
I asked this question earlier, but unfortunately the two replies I got did not solve the problem. Here it is again, but now with the code: After an Update my FormView always loses its viewstate...
3
by: Marcial | last post by:
Greetings all! After a week of toiling I've finallay decided to post the code below with hopes that someone can point out my error(s). Basically I have a Gridview/Formview on a ASP.NEt 2.0...
0
by: sanjeev06 | last post by:
When Updating using a FormView and ObjectDataSource, the formview always does the data-binding of its controls and the field values in the FormView are always overwritten by the results of the...
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
2
by: Matt MacDonald | last post by:
Hi all, I'm having an issue that's driving me crazy. I have a datatable that I need to display all the information for on a page. So, instead of manually coding every single column to a label, I...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
6
by: IReallyNeedHelp | last post by:
I have saved the questions using AddQuestion.aspx page i have created but i don't know how to display it and calculate their score. this is the formview i have done, but there is some error ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.