code prob, upgrading from traditional asp to asp.net

G

Guest

I have an application that I'm converting from traditional ASP to asp.net,
using visual basic to code with.

the line it doesn't like is: "If (sData(rownumber, lcnt) =
sData(rownumber - 1, lcnt)) AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6)
Then "

The error message is:


Server Error in '/test' Application.
----------------------------------------------------------------------------
----

Operator is not valid for type 'DBNull' and type 'Date'.
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: Operator is not valid for
type 'DBNull' and type 'Date'.

Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1,
lcnt)) AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then
Line 176: If rownumber = 3 Then
Line 177: thisfield = WhatCol.Value


In that, the Whatcol.Value is a null value.

What it's the result of is a SQL query in which I am doing a union join of 2
select statements. The field that it doesn't like is a date field, which is
set by using MAX(j5_org.inv_date). If the item hasn't had any shipments of
it, then I believe Null is a correct value for that field. At least, the
NULL shows up in the query as it's run in Query analyzer.

I'd rather fix my code than to go thru all of the stored procedures that'd
have a potential null value in them.

This application runs in traditional ASP, and the nulls do not seem to cause
a problem there, but they do in dotnet.


The Dotnet code it yaks on is:

For Each WhatCol In rstemp.Fields
'Load data to array
sData(rownumber, lcnt) = WhatCol.Value
'If Data Type is currency, real or float
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
GrandTotal(lcnt + 1, 0) = GrandTotal(lcnt + 1, 0) +
WhatCol.Value
End IF
'Suppress Duplicates for Printing
'Set up the first row for Grouping
If rownumber = 3 Then
sData(rownumber - 1, lcnt) = WhatCol.Value
End IF
If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND
(WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then
If rownumber = 3 Then
thisfield = WhatCol.Value
GroupField(lcnt) = GroupField(lcnt) + 1
Else
'Added the linecount < NrGroups times 2 which not
suppress duplicates on any field except Group Fields
'If you need to change it back insert (thisfield =
showblank) in place of If Statement.
If lcnt < (NrGroups * 2) + 1 Then
thisfield = showblank
GroupField(lcnt) = GroupField(lcnt) + 1
Else
thisfield = WhatCol.Value
End IF
End IF
Else
thisfield = sData(rownumber, lcnt)
GroupField(lcnt) = 0
End IF
'Total Rows Field Length is 1 Character
If Len(WhatCol.Name) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CDbl(thisfield), 0)
End IF


The original source code is:

<% lcnt = 0
' Prepare Row for Printing
for each WhatCol in rstemp.fields
'Load data to array
sData(rownumber,lcnt) = whatcol.value
if whatcol.type = 6 or whatcol.type = 5 then
grandTotal(lcnt+1,0) = grandTotal(lcnt+1,0) + whatcol.value
end if
' Suppress Duplicates for Printing
'Set up the first row for Grouping
If rownumber = 3 then
sdata(rownumber-1,lcnt) = whatcol.value
end if
if (sData(rownumber,lcnt) = sdata(rownumber-1,lcnt)) and (whatcol.type
<>5 and whatcol.type <> 6) then
if rownumber = 3 then
thisfield = whatcol.value
GroupField(lcnt) = GroupField(lcnt) + 1
else
' Added the linecount < NrGroups times 2 which not suppress duplicates on
any field except Group Fields
' If you need to change it back insert (thisfield = showblank) in place of
If Statement.
if lcnt < (nrGroups*2)+1 then
thisfield = showblank
GroupField(lcnt) = GroupField(lcnt) + 1
else
thisfield = whatcol.value
end if

end if
Else
thisfield = sData(rownumber,lcnt)
GroupField(lcnt) = 0
end if
' Total Rows Field Length is 1 Character
if len(whatcol.name) <> 1 then
if whatcol.type = 6 or whatcol.type = 5 then
thisfield = formatnumber(thisfield,0)
End If
%>

Any advice appreciated.

Thanks,

SC
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top