473,396 Members | 1,764 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,396 software developers and data experts.

Data conversion error

SAL
I'm sorry if this has been answered before but I didn't see it in a quick
scan of the list.
The following code is causing an error when the field is null:

Error text:
Conversion from type 'DBNull' to type 'Date' is not valid.

<asp:Calendar ID="Calendar2" runat="server" SelectedDate='<%#
Bind("DateReceived") %>'
VisibleDate='<%# Eval("DateReceived") %>'></asp:Calendar>

The control is a DetailsView and it's set up to enable editing.

How can I fix this. I new to asp.net and IIF doesn't seem to work.

Thanks
S
May 7 '07 #1
4 6219
On May 8, 12:39 am, "SAL" <S...@NoNo.comwrote:
I'm sorry if this has been answered before but I didn't see it in a quick
scan of the list.
The following code is causing an error when the field is null:

Error text:
Conversion from type 'DBNull' to type 'Date' is not valid.

<asp:Calendar ID="Calendar2" runat="server" SelectedDate='<%#
Bind("DateReceived") %>'
VisibleDate='<%# Eval("DateReceived") %>'></asp:Calendar>

The control is a DetailsView and it's set up to enable editing.

How can I fix this. I new to asp.net and IIF doesn't seem to work.
Your DateReceived is NULL and SelectedDate/VisibleDate supposed to
have a value. So, you should decide what date has to be selected when
there is no DateReceived returned and tell it the Calendar Control.

For example, you can show current date

In this case:

<asp:Calendar ID="Calendar2" runat="server"
SelectedDate='<%# IIf(IsDBNull(Bind("DateReceived")), DateTime.Now,
Bind("DateReceived")) %>'
VisibleDate='<%# IIf(IsDBNull(Bind("DateReceived")), DateTime.Now,
Bind("DateReceived")) %>'
></asp:Calendar>
or you can create a function

Function MyDate(ByVal o As Object) As DateTime
If o Is DBNull.Value Then
Return DateTime.Now
Else
Return o
End If
End Function

and use it in Calendar Control

<asp:Calendar ID="Calendar2" runat="server"
SelectedDate='<%# MyDate(Bind("DateReceived")) %>'
VisibleDate='<%# MyDate(Bind("DateReceived")) %>'
></asp:Calendar>
Hope it helps

May 8 '07 #2
SAL
Alexey,
thanks for the response and sorry for my delay. I was off work yesterday.

I tried wrapping it in a function and when I do that I get a compile error
that says the Bind variable has not been declared. That confuses the heck
out of me because when I wrap the Eval statement, I don't get a compile
error that say the Eval variable hasn't been declared. Any knowledge on
this?

Thanks
S

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
On May 8, 12:39 am, "SAL" <S...@NoNo.comwrote:
>I'm sorry if this has been answered before but I didn't see it in a quick
scan of the list.
The following code is causing an error when the field is null:

Error text:
Conversion from type 'DBNull' to type 'Date' is not valid.

<asp:Calendar ID="Calendar2" runat="server" SelectedDate='<%#
Bind("DateReceived") %>'
VisibleDate='<%# Eval("DateReceived") %>'></asp:Calendar>

The control is a DetailsView and it's set up to enable editing.

How can I fix this. I new to asp.net and IIF doesn't seem to work.

Your DateReceived is NULL and SelectedDate/VisibleDate supposed to
have a value. So, you should decide what date has to be selected when
there is no DateReceived returned and tell it the Calendar Control.

For example, you can show current date

In this case:

<asp:Calendar ID="Calendar2" runat="server"
SelectedDate='<%# IIf(IsDBNull(Bind("DateReceived")), DateTime.Now,
Bind("DateReceived")) %>'
VisibleDate='<%# IIf(IsDBNull(Bind("DateReceived")), DateTime.Now,
Bind("DateReceived")) %>'
>></asp:Calendar>

or you can create a function

Function MyDate(ByVal o As Object) As DateTime
If o Is DBNull.Value Then
Return DateTime.Now
Else
Return o
End If
End Function

and use it in Calendar Control

<asp:Calendar ID="Calendar2" runat="server"
SelectedDate='<%# MyDate(Bind("DateReceived")) %>'
VisibleDate='<%# MyDate(Bind("DateReceived")) %>'
>></asp:Calendar>

Hope it helps

May 9 '07 #3
On May 9, 5:59 pm, "SAL" <S...@NoNo.comwrote:
Alexey,
thanks for the response and sorry for my delay. I was off work yesterday.

I tried wrapping it in a function and when I do that I get a compile error
that says the Bind variable has not been declared. That confuses the heck
out of me because when I wrap the Eval statement, I don't get a compile
error that say the Eval variable hasn't been declared. Any knowledge on
this?
Please post the code of the datasource control/object, I will have a
look. There are some differences between Eval() and Bind(). The Eval
function is used to define one-way (read-only) binding. The Bind
function is used for two-way (updatable) binding.

Here's complete overview:
http://msdn2.microsoft.com/en-us/library/ms178366.aspx

May 9 '07 #4
SAL
It seems the problem is when there's a null value in this field however,
which is completely expected. There are many date fields that could be null
before editing a record.

Why the following compile error occurs when I wrap the Bind("DateReceived")
statement in the FixNullDate function I just don't get.
Here's the HTML for the EditItemTemplate for the DateReceived field in the
DetailsView:

<EditItemTemplate>
<asp:Calendar ID="Calendar2" runat="server" SelectedDate='<%#
Bind("DateReceived") %>'
VisibleDate='<%# FixNullDate(Eval("DateReceived")) %>'
></asp:Calendar>
</EditItemTemplate>

Here's the code for the FixNullDate function in the code behind page:
Function FixNullDate(ByVal dt As Object) As Date
If IsDBNull(dt) Then
Return Nothing
Else
Return dt
End If
End Function
This is the code in the business logic layer for updating a row:

Public Function UpdateAnnexation(ByVal annexationId As Integer, _
ByVal taxDistrictEntityId As Nullable(Of
Integer), _
ByVal dateReceived As Nullable(Of Date),
_
ByVal name As String, _
ByVal estimatedTaxImpacts As Nullable(Of
Decimal), _
ByVal estimatedAssessedValue As
Nullable(Of Decimal), _
ByVal acreage As Nullable(Of Single), _
ByVal gsReview As Nullable(Of DateTime),
_
ByVal legalOkay1 As Boolean, _
ByVal cityAnx As Nullable(Of DateTime),
_
ByVal statuteId As Nullable(Of Integer),
_
ByVal statuteRequirementsMet As Boolean,
_
ByVal ordinanceId As Nullable(Of
DateTime), _
ByVal legalOkay2 As Boolean, _
ByVal updateCities As Nullable(Of
DateTime), _
ByVal toLevySpecialist As Nullable(Of
DateTime), _
ByVal levySpecialistOkay As Boolean, _
ByVal updateCityAnx As Nullable(Of
DateTime), _
ByVal packetsSent As Nullable(Of
DateTime), _
ByVal ordinanceIn As Nullable(Of
DateTime), _
ByVal fromLevySpecialist As Nullable(Of
DateTime)) As Boolean
Adapter.UpdateAnnexation(taxDistrictEntityId, dateReceived, name,
estimatedTaxImpacts, _
acreage, estimatedAssessedValue, gsReview, legalOkay1, cityAnx,
statuteId, _
statuteRequirementsMet, ordinanceIn, legalOkay2, updateCities,
toLevySpecialist, _
levySpecialistOkay, fromLevySpecialist, updateCityAnx, packetsSent,
annexationId)
End Function
The code in the BLL for GetAnnexationByAnnexationID:

Public Function GetAnnexationByAnnexationId(ByVal annexationId As
Integer) As Annexationds.AnnexationsDataTable
Return Adapter.GetAnnexationByAnnexationId(annexationId)
End Function
And, here's the dataset queries:

To GetAnnexationByAnnexationID:

SELECT Acreage, AnnexationId, CityAnx, DateReceived,
EstimatedAssessedValue, EstimatedTaxImpacts, FromLevySpecialist, GSReview,
LegalOkay1, LegalOkay2, LevySpecialistOkay, Name, OrdinanceIn, PacketsSent,
StatuteId, StatuteRequirementsMet, TaxDistrictEntityId, ToLevySpecialist,
UpdateCities, UpdateCityAnx FROM Annexations WHERE (AnnexationId =
@AnnexationId)

And to UpdateAnnexation:

UPDATE Annexations
SET TaxDistrictEntityId = @TaxDistrictEntityId, DateReceived =
@DateReceived, Name = @Name, EstimatedTaxImpacts = @EstimatedTaxImpacts,
Acreage = @Acreage, EstimatedAssessedValue =
@EstimatedAssessedValue, GSReview = @GSReview, LegalOkay1 = @LegalOkay1,
CityAnx = @CityAnx, StatuteId = @StatuteId,
StatuteRequirementsMet = @StatuteRequirementsMet, OrdinanceIn =
@OrdinanceIn,
LegalOkay2 = @LegalOkay2, UpdateCities =
@UpdateCities, ToLevySpecialist = @ToLevySpecialist, LevySpecialistOkay =
@LevySpecialistOkay,
FromLevySpecialist = @FromLevySpecialist,
UpdateCityAnx = @UpdateCityAnx, PacketsSent = @PacketsSent
WHERE AnnexationId = @AnnexationId

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On May 9, 5:59 pm, "SAL" <S...@NoNo.comwrote:
>Alexey,
thanks for the response and sorry for my delay. I was off work yesterday.

I tried wrapping it in a function and when I do that I get a compile
error
that says the Bind variable has not been declared. That confuses the heck
out of me because when I wrap the Eval statement, I don't get a compile
error that say the Eval variable hasn't been declared. Any knowledge on
this?

Please post the code of the datasource control/object, I will have a
look. There are some differences between Eval() and Bind(). The Eval
function is used to define one-way (read-only) binding. The Bind
function is used for two-way (updatable) binding.

Here's complete overview:
http://msdn2.microsoft.com/en-us/library/ms178366.aspx

May 9 '07 #5

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

Similar topics

1
by: Balaji Neelakantan Pooruli | last post by:
Hi, We were in need of altering a DB2 table in which one of the column has been changed from VARCHAR(256) to INTEGER. I have extracted the table data into a tape before alters. After the alters...
6
by: Ecohouse | last post by:
I have a field in a recordset which is a string. It can look like this: 13-15-67-56 I need to break out this string into numbers to run in queries to open recordsets. But when I try to open...
2
by: Reggie | last post by:
Hi and TIA. I have a dataset that I fill from an Access table. Some integer and date fields are null. I'm iterating through the records and sending them to an SQL database table. The problem...
7
by: girl | last post by:
Hi i have a problem with MS SQL server 2000 and hope to seek for some advise. i have the following samples aa|0|abcdefg| b|0|abcdefg| i used the bulk insert in the query analyser.. BULK...
1
by: Javilen | last post by:
Hello, edit: added some more info I am trying to set up a job to run a SSIS package in SQL 2005, the SQL 2005 is installed on a Windows server 2003 machine. start Edit I have the...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
4
by: shalskedar | last post by:
I want to transfer the excel data to th Db ..thru the VBA code. In the DB there is a table called outer2 containing 1 of the columns as "Upvc" whose format is set to Long integer. When i try to...
2
by: dowlingm815 | last post by:
Hi, In the following code, i keep getting a data conversion error at the fund field. In the code below, it takes data from a query and creates a table. It is a six digit alpha field within the...
4
by: James Grant | last post by:
Hi Everyone, I've created a database (MS Access 2003) to help monitor staffing at my work. I now need to transcribe data from one table (tblPositions) into another (tblTeams) based on a common...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.