473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FormView Update fails with InvalidCastExce ption

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
InvalidCastExce ption. 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 1818
Sorry, I forgot to paste the code. Here it is.

<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="Tr ue"
DataKeyNames="P KId"
DataSourceID="S qlDataSource1">
<PagerSetting s Mode="NumericFi rstLast" />
<EditItemTempla te>
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="Description TextBox" runat="server" Text='<%#
Bind("Descripti on") %>'>
</asp:TextBox><br />
ItemNum:
<asp:TextBox ID="ItemNumText Box" runat="server" Text='<%#
Bind("ItemNum") %>'>
</asp:TextBox><br />
Modified:
<asp:TextBox ID="ModifiedTex tBox" runat="server" Text='<%#
Bind("Modified" ) %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
Name:
<asp:TextBox ID="NameTextBox " runat="server" Text='<%# Bind("Name") %>'>
</asp:TextBox><br />
Description:
<asp:TextBox ID="Description TextBox" runat="server" Text='<%#
Bind("Descripti on") %>'>
</asp:TextBox><br />
ItemNum:
<asp:TextBox ID="ItemNumText Box" runat="server" Text='<%#
Bind("ItemNum") %>'>
</asp:TextBox><br />
Modified:
<asp:TextBox ID="ModifiedTex tBox" runat="server" Text='<%#
Bind("Modified" ) %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<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="Description Label" runat="server" Text='<%#
Bind("Descripti on") %>'>
</asp:Label><br />
ItemNum:
<asp:Label ID="ItemNumLabe l" runat="server" Text='<%# Bind("ItemNum")
%>'></asp:Label><br />
Modified:
<asp:Label ID="ModifiedLab el" runat="server" Text='<%# Bind("Modified" )
%>'></asp:Label><br />
<asp:LinkButt on ID="EditButton " runat="server" CausesValidatio n="False"
CommandName="Ed it"
Text="Edit">
</asp:LinkButton>
<asp:LinkButt on ID="DeleteButto n" runat="server"
CausesValidatio n="False" CommandName="De lete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButt on ID="NewButton" runat="server" CausesValidatio n="False"
CommandName="Ne w"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:DataNozzleOr gConnectionStri ng %>"
DeleteCommand=" aaTableDelete" DeleteCommandTy pe="StoredProce dure"
InsertCommand=" aaTableInsert"
InsertCommandTy pe="StoredProce dure" SelectCommand=" aaTableSelectAl l"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" aaTableUpdate" UpdateCommandTy pe="StoredProce dure">
<DeleteParamete rs>
<asp:Paramete r Name="PKId" Type="Decimal" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:ControlPar ameter ControlID="Form View1" Name="PKId"
PropertyName="S electedValue"
Type="Decimal" />
<asp:ControlPar ameter ControlID="Form View1" Name="Name"
PropertyName="S electedValue"
Type="String" />
<asp:ControlPar ameter ControlID="Form View1" Name="Descripti on"
PropertyName="S electedValue"
Type="String" />
<asp:ControlPar ameter ControlID="Form View1" Name="ItemNum"
PropertyName="S electedValue"
Type="Decimal" />
<asp:ControlPar ameter ControlID="Form View1" Name="Modified"
PropertyName="S electedValue"
Type="DateTime" />
</UpdateParameter s>
<InsertParamete rs>
<asp:ControlPar ameter ControlID="Form View1" Direction="Inpu tOutput"
Name="PKId" PropertyName="S electedValue"
Type="Decimal" />
<asp:ControlPar ameter ControlID="Form View1" Name="Name"
PropertyName="S electedValue"
Type="String" />
<asp:ControlPar ameter ControlID="Form View1" Name="Descripti on"
PropertyName="S electedValue"
Type="String" />
<asp:ControlPar ameter ControlID="Form View1" Name="ItemNum"
PropertyName="S electedValue"
Type="Decimal" />
<asp:Paramete r Direction="Retu rnValue" Name="RETURN_VA LUE" Type="Int32"
/>
<asp:ControlPar ameter ControlID="Form View1" Name="Modified"
PropertyName="S electedValue"
Type="DateTime" />
</InsertParameter s>
</asp:SqlDataSour ce>
</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
InvalidCastExce ption. 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
6166
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& number, NumberFormatInfo info, Boolean parseDecimal) +2178925" This is beacuse some of my TextBoxes are empty (no value). If I enter a value it is OK. I need to use Null values to indicate that the field is not fileld in.
0
2198
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 .NET 2.0 DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be used in the ProviderName property of a SQLDataSource and loads properly at run time. The application I'm writing is a bit more complex than the example I'm about to...
3
3417
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 values. The field values in the FormView are always overwritten by the results of the Update method in the business layer. No matter what I do, the databind always takes place, even when I don't want it to. See the example below. This is a...
3
3084
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 page. When I select a record on the Gridview I'm presented with the corresponding FormView Template for Editing. Works fine! ItemTemplate in FormView works fine...Edit button takes me Edit Template!
0
1223
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 Update method. This behavior is fine when update method succeeds. But the problem is that when for some reason (e.g. a business rule "start date can not be prior to 1/1/2006") business layer rejects the data and Update method returns False (or...
3
3633
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" runat="server"></asp:Label></td> <td> <asp:TextBox ID="tbResponseText" runat="server" Text='<%#
2
2364
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 decided it would be easier and safer to use a formview to display it all, bound to an objectdatasource. Sounds simple enough. The problem is that many of my fields could potentially have null values, which produces an error similar to the...
4
8547
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 when it displays it shows values from the database and i have a link button edit on the ItemTemplate that changes the mode to edit mode and allows to edit the values which can be edited...
6
2266
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 <asp:FormView ID="FormView1" runat="server" DataKeyNames="QuestionID" DataSourceID="SqlDataSource1" Width="151px" AllowPaging="True"> <EditItemTemplate> QuestionID: ...
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.