- Home
- Forum
- ASP.NET Web Forms
- Cannot BIND to a NULL Database Field
Cannot BIND to a NULL Database Field
Hi Support Team,
I am using a DatePicker as an edit control in a Gridview column. Everything works fine if the database field that the DatePicker is bound to has a value. I can change and Update the field using the DataPicker.
When the database field does not have a value (NULL) I get the following error on clicking the row's "Edit" link:
Server Error in '/' Application.
Exception Details:System.InvalidCastException: Specified cast is not valid.
Source Error:
Source File:c:\iAM_iSTAR_fromRoger\iamistar\iamistar\Searches\EditParticipantData.aspx Line:277
Stack Trace:
Version Information:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1085.0
I am using Syncfusion.EJ.Web, Version=14.1400.0.41 with .NET version 4.6 and MS SQL Server database.
In this case, I want to see an empty DatePicker with WaterMark text "Select Date".Is there a workaround for this problem? I prefer to correct this in the aspx page mark-up, but I can work in the code-behind if needed.
Thanks in advance.
I am using a DatePicker as an edit control in a Gridview column. Everything works fine if the database field that the DatePicker is bound to has a value. I can change and Update the field using the DataPicker.
When the database field does not have a value (NULL) I get the following error on clicking the row's "Edit" link:
Server Error in '/' Application.
Specified cast is not valid.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details:System.InvalidCastException: Specified cast is not valid.
Source Error:
|
Source File:c:\iAM_iSTAR_fromRoger\iamistar\iamistar\Searches\EditParticipantData.aspx Line:277
Stack Trace:
|
Version Information:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1085.0
I am using Syncfusion.EJ.Web, Version=14.1400.0.41 with .NET version 4.6 and MS SQL Server database.
In this case, I want to see an empty DatePicker with WaterMark text "Select Date".Is there a workaround for this problem? I prefer to correct this in the aspx page mark-up, but I can work in the code-behind if needed.
Thanks in advance.
SIGN IN To post a reply.
3 Replies
TM
Thirukumaran Murugan
Syncfusion Team
September 29, 2016 04:31 PM UTC
Hi Jim,
Thanks for contacting Syncfusion support.
We would like to let you know that the DatePicker accepts both string, Date Time object values and we have tried to reproduce the issue by creating a simple DatePicker sample with MySQL database. In this we are able to set the fetched MySQL Date Time object value to the DatePicker as input.
Please check with the below link resolve the typecast error “ System.InvalidCastException: Specified cast is not valid.”
Query: I get the following error on clicking the row's "Edit" link:
Could you please explain more about this scenario or share the sample to reproduce the issue at our end? This will be helpful for us to analyze and provide a solution at the earliest.
Regards,
Thirukumaran M.
JL
Jim Lammy
September 29, 2016 05:38 PM UTC
Thank you Thirukumaran,
Your fast response is appreciated. The link you posted was very interesting.
I was able to get this to work in code-behind, the working GridView is below. I just hoped there would be a way to do this in the aspx mark-up (Wish List).

The "End Date" in the Update row of this record is blank in the database. The user can then select a new "End Date" or leave it blank for the Update.
Best regards,
Jim Lammy
Your fast response is appreciated. The link you posted was very interesting.
I was able to get this to work in code-behind, the working GridView is below. I just hoped there would be a way to do this in the aspx mark-up (Wish List).
The "End Date" in the Update row of this record is blank in the database. The user can then select a new "End Date" or leave it blank for the Update.
Best regards,
Jim Lammy
TM
Thirukumaran Murugan
Syncfusion Team
September 30, 2016 01:09 PM UTC
Hi Jim,
Yes, you can achieve your requirement in the aspx mark-up page itself.
Please refer to the below code snippet.
Code block:
|
// Define language as C# within the script tag.
<script language="c#" runat="server">
protected void Button1_Click(object sender, EventArgs e)
{ }
//Code behind logic.
</script>
|
In the above code block, we have defined the script tag with language as C#, to achieve the code behind logic within the ASPX markup page itself.
For your convenience we have attached the sample in the below link.
Sample location:
Regards,
Thirukumaran M.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JL Jim Lammy
- Sep 28, 2016 05:16 PM UTC
- Sep 30, 2016 01:09 PM UTC