473,748 Members | 4,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(rownumbe r, 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, and I am trying to return a date
field, which is calculated MAX(j5_org.invo ice_date). The item hasn't
shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET, because of
the error above.

Thanks,

SC
Nov 18 '05 #1
7 6264
If Not IsDBNull(WhatCo l.Value) then
all your code
End If

<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumbe r, 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, and I am trying to return a date field, which is calculated MAX(j5_org.invo ice_date). The item hasn't
shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET, because of
the error above.

Thanks,

SC

Nov 18 '05 #2
<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumbe r, 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, and I am trying to return a date field, which is calculated MAX(j5_org.invo ice_date). The item hasn't
shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET, because of
the error above.


Could you show us where you're getting WhatCol from?

A lot of things run in VBScript that don't run in VB.NET. That's because
VBScript allowed developers to get away with murder. If you really want to
improve your coding, turn Options Strict On. You'll find many places where
VB.NET was trying to "guess the right thing".
--
John Saunders
johnwsaundersii i at hotmail
Nov 18 '05 #3
The source data is from a SQL query that I'm running to display a web page.
Some sample results are:
BUSINESS AREA1 REPORTGROUP1 06-02-2004 50257.0000
BUSINESS AREA1 REPORTGROUP2 06-03-2004 30604.0000
BUSINESS AREA1 REPORTGROUP3 05-28-2004 2475.0000
BUSINESS AREA1 REPORTGROUP4 06-03-2004 7763.0000
BUSINESS AREA1 REPORTGROUP5 NULL 3.0000
BUSINESS AREA2 REPORTGROUP1 06-04-2004
219628.0000
BUSINESS AREA2 REPORTGROUP2 06-04-2004
126966.0000
BUSINESS AREA2 REPORTGROUP3 06-03-2004 2599.0000
BUSINESS AREA2 REPORTGROUP4 06-04-2004
692.0000
BUSINESS AREA2 REPORTGROUP5 06-04-2004
21805.0000
What it's doing is printing out the first column, then second column, and
then it dies, when it hits the date column that's null.

Like you said, VBScript would let you get away with some stuff, but I have
no idea why this null in a return dataset would cause this thing to give me
an error in dotnet. Traditional ASP didn't have a problem with it. I'm not
totaling on the field or anything, either.


The code to do the whole routine is here:

<tr>
<td><table border="9" align="center"
style="font-family: Arial; font-size: 9pt; border: medium none"
bordercolor="#0 00000">
<%
End IF
%>

<tr>
<%
'Put Headings On The Table of Field Names
'redim sData(rs.record count,175)
rownumber = 3
colnumber = 0
BeenThere = 0
lcnt = 0
numcols = 0
actualcols = 0
NrGroups = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
thisfield = WhatCol.Name
GroupField(lcnt ) = 0
numcols = numcols + 1
%>

<td bgcolor="#FFFFF F" align="center"> <p align="center"> <font
color="#000000" ><b><%= thisfield %></b></font></td>
<%
Else
'All 1 Character Field Names are Grouping Fields
'This sets up the grouping with hierachy determined from left to
right in SQL
GroupField(lcnt ) = 1
NrGroups = NrGroups + 1
End IF
actualcols = actualcols + 1
lcnt = lcnt + 1
Next
TBorder = "border:med ium none "
%>

</tr>
<%
'Now lets grab all the records
rownumber = 3
bgcolor = "white"
Do Until rstemp.EOF
%>

<tr>
<%
lcnt = 0
'Prepare Row for Printing
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(rownumbe r, 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.Nam e) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CD bl(thisfield), 0)
End IF
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border: medium none"><%= thisfield %>
<%
End IF
lcnt = lcnt + 1
Next
rstemp.MoveNext ()
'set or reset data
ralign = "right"
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
'End Totals and Grouping
lcnt = 0
If Not rstemp.EOF Then
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If WhatCol.Value.T oString() <> CStr(sData(rown umber,
lcnt)) Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
Else
'if rownumber<>3 then
rowCnt(lcnt) = rowCnt(lcnt) + 1
'end if
GroupField(lcnt ) = 0
End IF
lcnt = lcnt + 1
End IF
Next
End IF
If rstemp.EOF Then
lcnt = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If sData(rownumber - 1, lcnt) = sData(rownumber , lcnt)
AND CStr(sData(rown umber, lcnt)) <> "" Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
'rowcnt(lcnt) = rowcnt(lcnt)+1
Else
PrintTotal(lcnt ) = NrGroups + 1
'if rownumber<>3 then
rowCnt(lcnt) = 0
'end if
GroupField(lcnt ) = 0
End IF
'lcnt = lcnt + 1
End IF
lcnt = lcnt + 1
Next
End IF
lcnt = 0
iGroup = 0
For tcnt = 0 To NrGroups
pcnt = NrGroups - tcnt
If CInt(PrintTotal (pcnt)) < NrGroups AND (CInt(GroupFiel d(pcnt))
= 1 AND CInt(rowCnt(pcn t)) > 0) Then
GroupField(pcnt ) = 0
'rowcnt(pcnt) = 0
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
End IF
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
If CInt(rowCnt(pcn t)) < 1 AND (WhatCol.Type = 5 AND
WhatCol.Type = 6) Then
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type <> 5 AND
WhatCol.Type <> 6) Then
If lcnt = CInt((NrGroups) + PrintTotal(pcnt ))
Then
sTotals = CStr(sData(rown umber, lcnt))
'& "-" & rowcnt(pcnt) & WHATCOL.TYPE
Else
sTotals = showblank
End IF
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & sTotals &
"</FONT></STRONG></TD>")
End IF
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type = 5 Or
WhatCol.Type = 6) Then
For colcount = 0 To rowCnt(pcnt)
atotals = sData(rownumber - colcount, lcnt)
+ atotals
Next
atotals = FormatNumber(CD bl(atotals), 0)
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & atotals &
"</FONT></STRONG></TD>")
End IF
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
atotals = 0
End IF
End IF
lcnt = lcnt + 1
Next
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
BeenThere = BeenThere + 1
End IF
rowCnt(pcnt) = 0
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
End IF
lcnt = 0
Next
rownumber = rownumber + 1
Loop
%>

</td>
</tr>
<tr>
<%
'Grand Total Routine
lcnt = 0
col1 = 0
If NrGroups > 0 Then
'If any 1 character fields where defined, Grand Totals will appear
For Each WhatCol In rstemp.Fields
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
sTotal = FormatNumber(CD bl(GrandTotal(l cnt + 1, 0)), 0)
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= (sTotal)
%></strong>
<%
sTotal = 0
Else
If Len(WhatCol.Nam e) <> 1 Then
If col1 = 0 Then
sTotal1 = "Grand Total"
col1 = 1
Else
sTotal1 = showblank
End IF
Else
sTotal1 = showblank
End IF
If Len(WhatCol.Nam e) <> 1 Then
%>
</td>
<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= sTotal1
%></strong>
<%
End IF
End IF
lcnt = lcnt + 1
Next
%>
</td>
</tr>
<%
End IF
Session.Add("rp tend", Timer())
Session.Add("rp ttime", FormatNumber(CD bl(Session("rpt end")) -
CDbl(Session("r ptstart")), 1))
rstemp.Close()
rstemp = Nothing
conntemp.Close( )
conntemp = Nothing
%>

</table>
<p><small><%
Response.Write( "The report ran in " & Session("rpttim e") & " second(s)")
%>
</small></td>
</tr>
</table>


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:ub******** ******@TK2MSFTN GP11.phx.gbl...
<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumbe r, 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, and I am trying to return a

date
field, which is calculated MAX(j5_org.invo ice_date). The item hasn't
shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET, because of the error above.


Could you show us where you're getting WhatCol from?

A lot of things run in VBScript that don't run in VB.NET. That's because
VBScript allowed developers to get away with murder. If you really want to
improve your coding, turn Options Strict On. You'll find many places where
VB.NET was trying to "guess the right thing".
--
John Saunders
johnwsaundersii i at hotmail

Nov 18 '05 #4
I'll take a closer look at your code later, but the reason it doesn't let
you get away with it is that DBNull.Value is not the same thing as
String.Empty. It's also not the same thing as Nothing. In fact, DBNull is a
datatype with a single value, DBNull.Value. It can't be converted to or from
anything. It doesn't mean "blank", it means "I don't know". It's up to your
code to decide what "I don't know" means.

--
John Saunders
johnwsaundersii i at hotmail
<me@privacy.net > wrote in message
news:uW******** *****@TK2MSFTNG P10.phx.gbl...
The source data is from a SQL query that I'm running to display a web page. Some sample results are:
BUSINESS AREA1 REPORTGROUP1 06-02-2004 50257.0000
BUSINESS AREA1 REPORTGROUP2 06-03-2004 30604.0000
BUSINESS AREA1 REPORTGROUP3 05-28-2004 2475.0000
BUSINESS AREA1 REPORTGROUP4 06-03-2004 7763.0000
BUSINESS AREA1 REPORTGROUP5 NULL 3.0000
BUSINESS AREA2 REPORTGROUP1 06-04-2004
219628.0000
BUSINESS AREA2 REPORTGROUP2 06-04-2004
126966.0000
BUSINESS AREA2 REPORTGROUP3 06-03-2004 2599.0000
BUSINESS AREA2 REPORTGROUP4 06-04-2004
692.0000
BUSINESS AREA2 REPORTGROUP5 06-04-2004
21805.0000
What it's doing is printing out the first column, then second column, and
then it dies, when it hits the date column that's null.

Like you said, VBScript would let you get away with some stuff, but I have
no idea why this null in a return dataset would cause this thing to give me an error in dotnet. Traditional ASP didn't have a problem with it. I'm not totaling on the field or anything, either.


The code to do the whole routine is here:

<tr>
<td><table border="9" align="center"
style="font-family: Arial; font-size: 9pt; border: medium none"
bordercolor="#0 00000">
<%
End IF
%>

<tr>
<%
'Put Headings On The Table of Field Names
'redim sData(rs.record count,175)
rownumber = 3
colnumber = 0
BeenThere = 0
lcnt = 0
numcols = 0
actualcols = 0
NrGroups = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
thisfield = WhatCol.Name
GroupField(lcnt ) = 0
numcols = numcols + 1
%>

<td bgcolor="#FFFFF F" align="center"> <p align="center"> <font
color="#000000" ><b><%= thisfield %></b></font></td>
<%
Else
'All 1 Character Field Names are Grouping Fields
'This sets up the grouping with hierachy determined from left to right in SQL
GroupField(lcnt ) = 1
NrGroups = NrGroups + 1
End IF
actualcols = actualcols + 1
lcnt = lcnt + 1
Next
TBorder = "border:med ium none "
%>

</tr>
<%
'Now lets grab all the records
rownumber = 3
bgcolor = "white"
Do Until rstemp.EOF
%>

<tr>
<%
lcnt = 0
'Prepare Row for Printing
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(rownumbe r, 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.Nam e) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CD bl(thisfield), 0)
End IF
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border: medium none"><%= thisfield %>
<%
End IF
lcnt = lcnt + 1
Next
rstemp.MoveNext ()
'set or reset data
ralign = "right"
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
'End Totals and Grouping
lcnt = 0
If Not rstemp.EOF Then
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If WhatCol.Value.T oString() <> CStr(sData(rown umber,
lcnt)) Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
Else
'if rownumber<>3 then
rowCnt(lcnt) = rowCnt(lcnt) + 1
'end if
GroupField(lcnt ) = 0
End IF
lcnt = lcnt + 1
End IF
Next
End IF
If rstemp.EOF Then
lcnt = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If sData(rownumber - 1, lcnt) = sData(rownumber , lcnt)
AND CStr(sData(rown umber, lcnt)) <> "" Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
'rowcnt(lcnt) = rowcnt(lcnt)+1
Else
PrintTotal(lcnt ) = NrGroups + 1
'if rownumber<>3 then
rowCnt(lcnt) = 0
'end if
GroupField(lcnt ) = 0
End IF
'lcnt = lcnt + 1
End IF
lcnt = lcnt + 1
Next
End IF
lcnt = 0
iGroup = 0
For tcnt = 0 To NrGroups
pcnt = NrGroups - tcnt
If CInt(PrintTotal (pcnt)) < NrGroups AND (CInt(GroupFiel d(pcnt)) = 1 AND CInt(rowCnt(pcn t)) > 0) Then
GroupField(pcnt ) = 0
'rowcnt(pcnt) = 0
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
End IF
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
If CInt(rowCnt(pcn t)) < 1 AND (WhatCol.Type = 5 AND WhatCol.Type = 6) Then
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then
If lcnt = CInt((NrGroups) + PrintTotal(pcnt ))
Then
sTotals = CStr(sData(rown umber, lcnt))
'& "-" & rowcnt(pcnt) & WHATCOL.TYPE
Else
sTotals = showblank
End IF
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & sTotals &
"</FONT></STRONG></TD>")
End IF
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type = 5 Or
WhatCol.Type = 6) Then
For colcount = 0 To rowCnt(pcnt)
atotals = sData(rownumber - colcount, lcnt) + atotals
Next
atotals = FormatNumber(CD bl(atotals), 0)
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & atotals &
"</FONT></STRONG></TD>")
End IF
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
atotals = 0
End IF
End IF
lcnt = lcnt + 1
Next
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
BeenThere = BeenThere + 1
End IF
rowCnt(pcnt) = 0
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
End IF
lcnt = 0
Next
rownumber = rownumber + 1
Loop
%>

</td>
</tr>
<tr>
<%
'Grand Total Routine
lcnt = 0
col1 = 0
If NrGroups > 0 Then
'If any 1 character fields where defined, Grand Totals will appear
For Each WhatCol In rstemp.Fields
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
sTotal = FormatNumber(CD bl(GrandTotal(l cnt + 1, 0)), 0)
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= (sTotal) %></strong>
<%
sTotal = 0
Else
If Len(WhatCol.Nam e) <> 1 Then
If col1 = 0 Then
sTotal1 = "Grand Total"
col1 = 1
Else
sTotal1 = showblank
End IF
Else
sTotal1 = showblank
End IF
If Len(WhatCol.Nam e) <> 1 Then
%>
</td>
<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= sTotal1
%></strong>
<%
End IF
End IF
lcnt = lcnt + 1
Next
%>
</td>
</tr>
<%
End IF
Session.Add("rp tend", Timer())
Session.Add("rp ttime", FormatNumber(CD bl(Session("rpt end")) -
CDbl(Session("r ptstart")), 1))
rstemp.Close()
rstemp = Nothing
conntemp.Close( )
conntemp = Nothing
%>

</table>
<p><small><%
Response.Write( "The report ran in " & Session("rpttim e") & " second(s)") %>
</small></td>
</tr>
</table>


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:ub******** ******@TK2MSFTN GP11.phx.gbl...
<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumbe r, 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, and I am trying to return a
date
field, which is calculated MAX(j5_org.invo ice_date). The item
hasn't shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET,
because
of the error above.


Could you show us where you're getting WhatCol from?

A lot of things run in VBScript that don't run in VB.NET. That's because
VBScript allowed developers to get away with murder. If you really want

to improve your coding, turn Options Strict On. You'll find many places where VB.NET was trying to "guess the right thing".
--
John Saunders
johnwsaundersii i at hotmail


Nov 18 '05 #5
You really should leave this as a classic ASP page until you are ready to
fully convert it to ASP .NET. You are still using all the classic ASP
methodologies in an ASP .NET architecture. You'll find that using a
DataGrid and binding it to the data returned from your query is much easier
than all the inline coding that you are doing.

And, from my earlier post, if you check a field for DBNull (either by
comparing against DBNull.Value or using IsDBNull(field) ) before you attempt
to use it, you're problem will be solved.
<me@privacy.net > wrote in message
news:uW******** *****@TK2MSFTNG P10.phx.gbl...
The source data is from a SQL query that I'm running to display a web page. Some sample results are:
BUSINESS AREA1 REPORTGROUP1 06-02-2004 50257.0000
BUSINESS AREA1 REPORTGROUP2 06-03-2004 30604.0000
BUSINESS AREA1 REPORTGROUP3 05-28-2004 2475.0000
BUSINESS AREA1 REPORTGROUP4 06-03-2004 7763.0000
BUSINESS AREA1 REPORTGROUP5 NULL 3.0000
BUSINESS AREA2 REPORTGROUP1 06-04-2004
219628.0000
BUSINESS AREA2 REPORTGROUP2 06-04-2004
126966.0000
BUSINESS AREA2 REPORTGROUP3 06-03-2004 2599.0000
BUSINESS AREA2 REPORTGROUP4 06-04-2004
692.0000
BUSINESS AREA2 REPORTGROUP5 06-04-2004
21805.0000
What it's doing is printing out the first column, then second column, and
then it dies, when it hits the date column that's null.

Like you said, VBScript would let you get away with some stuff, but I have
no idea why this null in a return dataset would cause this thing to give me an error in dotnet. Traditional ASP didn't have a problem with it. I'm not totaling on the field or anything, either.


The code to do the whole routine is here:

<tr>
<td><table border="9" align="center"
style="font-family: Arial; font-size: 9pt; border: medium none"
bordercolor="#0 00000">
<%
End IF
%>

<tr>
<%
'Put Headings On The Table of Field Names
'redim sData(rs.record count,175)
rownumber = 3
colnumber = 0
BeenThere = 0
lcnt = 0
numcols = 0
actualcols = 0
NrGroups = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
thisfield = WhatCol.Name
GroupField(lcnt ) = 0
numcols = numcols + 1
%>

<td bgcolor="#FFFFF F" align="center"> <p align="center"> <font
color="#000000" ><b><%= thisfield %></b></font></td>
<%
Else
'All 1 Character Field Names are Grouping Fields
'This sets up the grouping with hierachy determined from left to right in SQL
GroupField(lcnt ) = 1
NrGroups = NrGroups + 1
End IF
actualcols = actualcols + 1
lcnt = lcnt + 1
Next
TBorder = "border:med ium none "
%>

</tr>
<%
'Now lets grab all the records
rownumber = 3
bgcolor = "white"
Do Until rstemp.EOF
%>

<tr>
<%
lcnt = 0
'Prepare Row for Printing
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(rownumbe r, 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.Nam e) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CD bl(thisfield), 0)
End IF
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border: medium none"><%= thisfield %>
<%
End IF
lcnt = lcnt + 1
Next
rstemp.MoveNext ()
'set or reset data
ralign = "right"
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
'End Totals and Grouping
lcnt = 0
If Not rstemp.EOF Then
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If WhatCol.Value.T oString() <> CStr(sData(rown umber,
lcnt)) Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
Else
'if rownumber<>3 then
rowCnt(lcnt) = rowCnt(lcnt) + 1
'end if
GroupField(lcnt ) = 0
End IF
lcnt = lcnt + 1
End IF
Next
End IF
If rstemp.EOF Then
lcnt = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If sData(rownumber - 1, lcnt) = sData(rownumber , lcnt)
AND CStr(sData(rown umber, lcnt)) <> "" Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
'rowcnt(lcnt) = rowcnt(lcnt)+1
Else
PrintTotal(lcnt ) = NrGroups + 1
'if rownumber<>3 then
rowCnt(lcnt) = 0
'end if
GroupField(lcnt ) = 0
End IF
'lcnt = lcnt + 1
End IF
lcnt = lcnt + 1
Next
End IF
lcnt = 0
iGroup = 0
For tcnt = 0 To NrGroups
pcnt = NrGroups - tcnt
If CInt(PrintTotal (pcnt)) < NrGroups AND (CInt(GroupFiel d(pcnt)) = 1 AND CInt(rowCnt(pcn t)) > 0) Then
GroupField(pcnt ) = 0
'rowcnt(pcnt) = 0
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
End IF
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
If CInt(rowCnt(pcn t)) < 1 AND (WhatCol.Type = 5 AND WhatCol.Type = 6) Then
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type <> 5 AND WhatCol.Type <> 6) Then
If lcnt = CInt((NrGroups) + PrintTotal(pcnt ))
Then
sTotals = CStr(sData(rown umber, lcnt))
'& "-" & rowcnt(pcnt) & WHATCOL.TYPE
Else
sTotals = showblank
End IF
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & sTotals &
"</FONT></STRONG></TD>")
End IF
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type = 5 Or
WhatCol.Type = 6) Then
For colcount = 0 To rowCnt(pcnt)
atotals = sData(rownumber - colcount, lcnt) + atotals
Next
atotals = FormatNumber(CD bl(atotals), 0)
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & "
ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & atotals &
"</FONT></STRONG></TD>")
End IF
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
atotals = 0
End IF
End IF
lcnt = lcnt + 1
Next
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
BeenThere = BeenThere + 1
End IF
rowCnt(pcnt) = 0
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
End IF
lcnt = 0
Next
rownumber = rownumber + 1
Loop
%>

</td>
</tr>
<tr>
<%
'Grand Total Routine
lcnt = 0
col1 = 0
If NrGroups > 0 Then
'If any 1 character fields where defined, Grand Totals will appear
For Each WhatCol In rstemp.Fields
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
sTotal = FormatNumber(CD bl(GrandTotal(l cnt + 1, 0)), 0)
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= (sTotal) %></strong>
<%
sTotal = 0
Else
If Len(WhatCol.Nam e) <> 1 Then
If col1 = 0 Then
sTotal1 = "Grand Total"
col1 = 1
Else
sTotal1 = showblank
End IF
Else
sTotal1 = showblank
End IF
If Len(WhatCol.Nam e) <> 1 Then
%>
</td>
<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= sTotal1
%></strong>
<%
End IF
End IF
lcnt = lcnt + 1
Next
%>
</td>
</tr>
<%
End IF
Session.Add("rp tend", Timer())
Session.Add("rp ttime", FormatNumber(CD bl(Session("rpt end")) -
CDbl(Session("r ptstart")), 1))
rstemp.Close()
rstemp = Nothing
conntemp.Close( )
conntemp = Nothing
%>

</table>
<p><small><%
Response.Write( "The report ran in " & Session("rpttim e") & " second(s)") %>
</small></td>
</tr>
</table>


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:ub******** ******@TK2MSFTN GP11.phx.gbl...
<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
Source Error:

Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
Line 174: End IF
Line 175: If (sData(rownumbe r, 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, and I am trying to return a
date
field, which is calculated MAX(j5_org.invo ice_date). The item
hasn't shipped, so it doesn't return a shipped date.

How can I get this code resolved to where it doesn't blow up on this?

This code runs in traditional ASP, but does not run in ASP.NET,
because
of the error above.


Could you show us where you're getting WhatCol from?

A lot of things run in VBScript that don't run in VB.NET. That's because
VBScript allowed developers to get away with murder. If you really want

to improve your coding, turn Options Strict On. You'll find many places where VB.NET was trying to "guess the right thing".
--
John Saunders
johnwsaundersii i at hotmail


Nov 18 '05 #6
<<You really should leave this as a classic ASP page until you are ready to
fully convert it to ASP .NET. You are still using all the classic ASP
methodologies in an ASP .NET architecture. You'll find that using a
DataGrid and binding it to the data returned from your query is much easier
than all the inline coding that you are doing.>>

We had started doing exactly what you're describing. However, we
encountered a problem for which I have been unable to find a solution. That
problem was saving to Excel. Lots of the reports we create, our users will
save them to excel and work with them, in terms of developing forecasts,
etc. With the controls on screen, we found that we had a little better than
a 50% failure rate in either opening the file in excel, or if the report was
a large one, it'd prompt you a number of times for a user id & password and
wouldn't ever produce the excel sheet. The problem in the opening the file
in excel was due directly to the controls being on the screen. Since we
have a number of variables that go in to producing the reports, it was
impractical to try to convert a 2nd page that'd load the report in a format
that COULD be saved and opened in Excel.

I posted the problem I had with both of them numerous times in one of the
framework.aspne t groups, and was never able to find a satisfactory
resolution. At that point, we decided to just take our traditional asp
application, and convert it to dotnet, when we found that a number of the
reports we generated all would save & open in Excel, when we created them
with the converted report writer.

<<And, from my earlier post, if you check a field for DBNull (either by
comparing against DBNull.Value or using IsDBNull(field) ) before you attempt
to use it, you're problem will be solved.>>

I've tried this, but evidently, I did not have the check in the right place.

I had:

If Not IsDBNull(WhatCo l.Value) then
If (sData(rownumbe r, 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
Else
thisfield = sData(rownumber ,lcnt)
GroupField(lcnt ) = 0
End if

It still gave me the dbnull error.

SC



<me@privacy.net > wrote in message
news:uW******** *****@TK2MSFTNG P10.phx.gbl...
The source data is from a SQL query that I'm running to display a web page.
Some sample results are:
BUSINESS AREA1 REPORTGROUP1 06-02-2004 50257.0000
BUSINESS AREA1 REPORTGROUP2 06-03-2004 30604.0000
BUSINESS AREA1 REPORTGROUP3 05-28-2004 2475.0000 BUSINESS AREA1 REPORTGROUP4 06-03-2004 7763.0000
BUSINESS AREA1 REPORTGROUP5 NULL 3.0000
BUSINESS AREA2 REPORTGROUP1 06-04-2004
219628.0000
BUSINESS AREA2 REPORTGROUP2 06-04-2004
126966.0000
BUSINESS AREA2 REPORTGROUP3 06-03-2004 2599.0000 BUSINESS AREA2 REPORTGROUP4 06-04-2004
692.0000
BUSINESS AREA2 REPORTGROUP5 06-04-2004
21805.0000
What it's doing is printing out the first column, then second column, and then it dies, when it hits the date column that's null.

Like you said, VBScript would let you get away with some stuff, but I have no idea why this null in a return dataset would cause this thing to give

me
an error in dotnet. Traditional ASP didn't have a problem with it. I'm

not
totaling on the field or anything, either.


The code to do the whole routine is here:

<tr>
<td><table border="9" align="center"
style="font-family: Arial; font-size: 9pt; border: medium none"
bordercolor="#0 00000">
<%
End IF
%>

<tr>
<%
'Put Headings On The Table of Field Names
'redim sData(rs.record count,175)
rownumber = 3
colnumber = 0
BeenThere = 0
lcnt = 0
numcols = 0
actualcols = 0
NrGroups = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
thisfield = WhatCol.Name
GroupField(lcnt ) = 0
numcols = numcols + 1
%>

<td bgcolor="#FFFFF F" align="center"> <p align="center"> <font
color="#000000" ><b><%= thisfield %></b></font></td>
<%
Else
'All 1 Character Field Names are Grouping Fields
'This sets up the grouping with hierachy determined from left to
right in SQL
GroupField(lcnt ) = 1
NrGroups = NrGroups + 1
End IF
actualcols = actualcols + 1
lcnt = lcnt + 1
Next
TBorder = "border:med ium none "
%>

</tr>
<%
'Now lets grab all the records
rownumber = 3
bgcolor = "white"
Do Until rstemp.EOF
%>

<tr>
<%
lcnt = 0
'Prepare Row for Printing
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(rownumbe r, 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.Nam e) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CD bl(thisfield), 0)
End IF
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border: medium none"><%= thisfield %>
<%
End IF
lcnt = lcnt + 1
Next
rstemp.MoveNext ()
'set or reset data
ralign = "right"
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
'End Totals and Grouping
lcnt = 0
If Not rstemp.EOF Then
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If WhatCol.Value.T oString() <> CStr(sData(rown umber,
lcnt)) Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
Else
'if rownumber<>3 then
rowCnt(lcnt) = rowCnt(lcnt) + 1
'end if
GroupField(lcnt ) = 0
End IF
lcnt = lcnt + 1
End IF
Next
End IF
If rstemp.EOF Then
lcnt = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If sData(rownumber - 1, lcnt) = sData(rownumber ,
lcnt) AND CStr(sData(rown umber, lcnt)) <> "" Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
'rowcnt(lcnt) = rowcnt(lcnt)+1
Else
PrintTotal(lcnt ) = NrGroups + 1
'if rownumber<>3 then
rowCnt(lcnt) = 0
'end if
GroupField(lcnt ) = 0
End IF
'lcnt = lcnt + 1
End IF
lcnt = lcnt + 1
Next
End IF
lcnt = 0
iGroup = 0
For tcnt = 0 To NrGroups
pcnt = NrGroups - tcnt
If CInt(PrintTotal (pcnt)) < NrGroups AND

(CInt(GroupFiel d(pcnt))
= 1 AND CInt(rowCnt(pcn t)) > 0) Then
GroupField(pcnt ) = 0
'rowcnt(pcnt) = 0
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
End IF
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
If CInt(rowCnt(pcn t)) < 1 AND (WhatCol.Type = 5

AND
WhatCol.Type = 6) Then
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type <> 5

AND
WhatCol.Type <> 6) Then
If lcnt = CInt((NrGroups) + PrintTotal(pcnt )) Then
sTotals = CStr(sData(rown umber, lcnt))
'& "-" & rowcnt(pcnt) & WHATCOL.TYPE
Else
sTotals = showblank
End IF
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & " ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & sTotals &
"</FONT></STRONG></TD>")
End IF
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type = 5 Or WhatCol.Type = 6) Then
For colcount = 0 To rowCnt(pcnt)
atotals = sData(rownumber - colcount,

lcnt)
+ atotals
Next
atotals = FormatNumber(CD bl(atotals), 0)
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder & " ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & atotals &
"</FONT></STRONG></TD>")
End IF
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
atotals = 0
End IF
End IF
lcnt = lcnt + 1
Next
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
BeenThere = BeenThere + 1
End IF
rowCnt(pcnt) = 0
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
End IF
lcnt = 0
Next
rownumber = rownumber + 1
Loop
%>

</td>
</tr>
<tr>
<%
'Grand Total Routine
lcnt = 0
col1 = 0
If NrGroups > 0 Then
'If any 1 character fields where defined, Grand Totals will appear For Each WhatCol In rstemp.Fields
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
sTotal = FormatNumber(CD bl(GrandTotal(l cnt + 1, 0)), 0)
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %=

(sTotal)
%></strong>
<%
sTotal = 0
Else
If Len(WhatCol.Nam e) <> 1 Then
If col1 = 0 Then
sTotal1 = "Grand Total"
col1 = 1
Else
sTotal1 = showblank
End IF
Else
sTotal1 = showblank
End IF
If Len(WhatCol.Nam e) <> 1 Then
%>
</td>
<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= sTotal1 %></strong>
<%
End IF
End IF
lcnt = lcnt + 1
Next
%>
</td>
</tr>
<%
End IF
Session.Add("rp tend", Timer())
Session.Add("rp ttime", FormatNumber(CD bl(Session("rpt end")) -
CDbl(Session("r ptstart")), 1))
rstemp.Close()
rstemp = Nothing
conntemp.Close( )
conntemp = Nothing
%>

</table>
<p><small><%
Response.Write( "The report ran in " & Session("rpttim e") & "

second(s)")
%>
</small></td>
</tr>
</table>


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:ub******** ******@TK2MSFTN GP11.phx.gbl...
<me@privacy.net > wrote in message
news:Ow******** ******@tk2msftn gp13.phx.gbl...
> Source Error:
>
> Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value
> Line 174: End IF
> Line 175: If (sData(rownumbe r, 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, and I am trying to return a date
> field, which is calculated MAX(j5_org.invo ice_date). The item hasn't > shipped, so it doesn't return a shipped date.
>
> How can I get this code resolved to where it doesn't blow up on
this? >
> This code runs in traditional ASP, but does not run in ASP.NET,
because
of
> the error above.

Could you show us where you're getting WhatCol from?

A lot of things run in VBScript that don't run in VB.NET. That's because VBScript allowed developers to get away with murder. If you really

want to improve your coding, turn Options Strict On. You'll find many places where VB.NET was trying to "guess the right thing".
--
John Saunders
johnwsaundersii i at hotmail



Nov 18 '05 #7
Well, my advice would be to re-write this code using .NET strategies and
classes, rather that just making your classic ASP code "work" inside of
..NET.

It's hard to tell exactly what the code you posted is doing because it is
incomplete. Perhaps if you posted the whole sub-routine....
<me@privacy.net > wrote in message
news:um******** ******@tk2msftn gp13.phx.gbl...
<<You really should leave this as a classic ASP page until you are ready to fully convert it to ASP .NET. You are still using all the classic ASP
methodologies in an ASP .NET architecture. You'll find that using a
DataGrid and binding it to the data returned from your query is much easier than all the inline coding that you are doing.>>

We had started doing exactly what you're describing. However, we
encountered a problem for which I have been unable to find a solution. That problem was saving to Excel. Lots of the reports we create, our users will save them to excel and work with them, in terms of developing forecasts,
etc. With the controls on screen, we found that we had a little better than a 50% failure rate in either opening the file in excel, or if the report was a large one, it'd prompt you a number of times for a user id & password and wouldn't ever produce the excel sheet. The problem in the opening the file in excel was due directly to the controls being on the screen. Since we
have a number of variables that go in to producing the reports, it was
impractical to try to convert a 2nd page that'd load the report in a format that COULD be saved and opened in Excel.

I posted the problem I had with both of them numerous times in one of the
framework.aspne t groups, and was never able to find a satisfactory
resolution. At that point, we decided to just take our traditional asp
application, and convert it to dotnet, when we found that a number of the
reports we generated all would save & open in Excel, when we created them
with the converted report writer.

<<And, from my earlier post, if you check a field for DBNull (either by
comparing against DBNull.Value or using IsDBNull(field) ) before you attempt to use it, you're problem will be solved.>>

I've tried this, but evidently, I did not have the check in the right place.
I had:

If Not IsDBNull(WhatCo l.Value) then
If (sData(rownumbe r, 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
Else
thisfield = sData(rownumber ,lcnt)
GroupField(lcnt ) = 0
End if

It still gave me the dbnull error.

SC



<me@privacy.net > wrote in message
news:uW******** *****@TK2MSFTNG P10.phx.gbl...
The source data is from a SQL query that I'm running to display a web page.
Some sample results are:
BUSINESS AREA1 REPORTGROUP1 06-02-2004 50257.0000 BUSINESS AREA1 REPORTGROUP2 06-03-2004 30604.0000 BUSINESS AREA1 REPORTGROUP3 05-28-2004 2475.0000 BUSINESS AREA1 REPORTGROUP4 06-03-2004 7763.0000
BUSINESS AREA1 REPORTGROUP5 NULL 3.0000
BUSINESS AREA2 REPORTGROUP1 06-04-2004 219628.0000
BUSINESS AREA2 REPORTGROUP2 06-04-2004
126966.0000
BUSINESS AREA2 REPORTGROUP3 06-03-2004 2599.0000 BUSINESS AREA2 REPORTGROUP4 06-04-2004
692.0000
BUSINESS AREA2 REPORTGROUP5 06-04-2004
21805.0000
What it's doing is printing out the first column, then second column, and then it dies, when it hits the date column that's null.

Like you said, VBScript would let you get away with some stuff, but I have no idea why this null in a return dataset would cause this thing to give
me
an error in dotnet. Traditional ASP didn't have a problem with it.
I'm
not
totaling on the field or anything, either.


The code to do the whole routine is here:

<tr>
<td><table border="9" align="center"
style="font-family: Arial; font-size: 9pt; border: medium none"
bordercolor="#0 00000">
<%
End IF
%>

<tr>
<%
'Put Headings On The Table of Field Names
'redim sData(rs.record count,175)
rownumber = 3
colnumber = 0
BeenThere = 0
lcnt = 0
numcols = 0
actualcols = 0
NrGroups = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
thisfield = WhatCol.Name
GroupField(lcnt ) = 0
numcols = numcols + 1
%>

<td bgcolor="#FFFFF F" align="center"> <p align="center"> <font
color="#000000" ><b><%= thisfield %></b></font></td>
<%
Else
'All 1 Character Field Names are Grouping Fields
'This sets up the grouping with hierachy determined from left
to
right in SQL
GroupField(lcnt ) = 1
NrGroups = NrGroups + 1
End IF
actualcols = actualcols + 1
lcnt = lcnt + 1
Next
TBorder = "border:med ium none "
%>

</tr>
<%
'Now lets grab all the records
rownumber = 3
bgcolor = "white"
Do Until rstemp.EOF
%>

<tr>
<%
lcnt = 0
'Prepare Row for Printing
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(rownumbe r, 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.Nam e) <> 1 Then
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
thisfield = FormatNumber(CD bl(thisfield), 0)
End IF
%>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border: medium none"><%= thisfield %>
<%
End IF
lcnt = lcnt + 1
Next
rstemp.MoveNext ()
'set or reset data
ralign = "right"
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
'End Totals and Grouping
lcnt = 0
If Not rstemp.EOF Then
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If WhatCol.Value.T oString() <> CStr(sData(rown umber, lcnt)) Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
Else
'if rownumber<>3 then
rowCnt(lcnt) = rowCnt(lcnt) + 1
'end if
GroupField(lcnt ) = 0
End IF
lcnt = lcnt + 1
End IF
Next
End IF
If rstemp.EOF Then
lcnt = 0
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) = 1 Then
If sData(rownumber - 1, lcnt) = sData(rownumber ,

lcnt) AND CStr(sData(rown umber, lcnt)) <> "" Then
PrintTotal(lcnt ) = lcnt
GroupField(lcnt ) = 1
'rowcnt(lcnt) = rowcnt(lcnt)+1
Else
PrintTotal(lcnt ) = NrGroups + 1
'if rownumber<>3 then
rowCnt(lcnt) = 0
'end if
GroupField(lcnt ) = 0
End IF
'lcnt = lcnt + 1
End IF
lcnt = lcnt + 1
Next
End IF
lcnt = 0
iGroup = 0
For tcnt = 0 To NrGroups
pcnt = NrGroups - tcnt
If CInt(PrintTotal (pcnt)) < NrGroups AND

(CInt(GroupFiel d(pcnt))
= 1 AND CInt(rowCnt(pcn t)) > 0) Then
GroupField(pcnt ) = 0
'rowcnt(pcnt) = 0
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
End IF
For Each WhatCol In rstemp.Fields
If Len(WhatCol.Nam e) <> 1 Then
If CInt(rowCnt(pcn t)) < 1 AND (WhatCol.Type = 5 AND
WhatCol.Type = 6) Then
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type <>
5
AND
WhatCol.Type <> 6) Then
If lcnt = CInt((NrGroups) +

PrintTotal(pcnt )) Then
sTotals = CStr(sData(rown umber, lcnt))
'& "-" & rowcnt(pcnt) & WHATCOL.TYPE
Else
sTotals = showblank
End IF
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder
& " ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & sTotals &
"</FONT></STRONG></TD>")
End IF
End IF
If Len(WhatCol.Nam e) <> 1 AND (WhatCol.Type =
5
Or WhatCol.Type = 6) Then
For colcount = 0 To rowCnt(pcnt)
atotals = sData(rownumber - colcount, lcnt)
+ atotals
Next
atotals = FormatNumber(CD bl(atotals), 0)
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "<TD style=" & TBorder
& " ALIGN=" & ralign & " BGCOLOR=" & bgcolor & "><STRONG>" & atotals &
"</FONT></STRONG></TD>")
End IF
GrpTotal(lcnt, PrintTotal(pcnt )) = 0
atotals = 0
End IF
End IF
lcnt = lcnt + 1
Next
If CInt(rowCnt(pcn t)) > 0 Then
Response.Write( "</tr><tr>")
BeenThere = BeenThere + 1
End IF
rowCnt(pcnt) = 0
'Change colors for every other line
If chgcolor = 0 Then
bgcolor = "#FFFFCC"
chgcolor = 1
Else
bgcolor = "White"
chgcolor = 0
End IF
End IF
lcnt = 0
Next
rownumber = rownumber + 1
Loop
%>

</td>
</tr>
<tr>
<%
'Grand Total Routine
lcnt = 0
col1 = 0
If NrGroups > 0 Then
'If any 1 character fields where defined, Grand Totals will appear For Each WhatCol In rstemp.Fields
If WhatCol.Type = 6 Or WhatCol.Type = 5 Then
sTotal = FormatNumber(CD bl(GrandTotal(l cnt + 1, 0)),
0) %>

<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %= (sTotal)
%></strong>
<%
sTotal = 0
Else
If Len(WhatCol.Nam e) <> 1 Then
If col1 = 0 Then
sTotal1 = "Grand Total"
col1 = 1
Else
sTotal1 = showblank
End IF
Else
sTotal1 = showblank
End IF
If Len(WhatCol.Nam e) <> 1 Then
%>
</td>
<td bgcolor="<%= bgcolor %>" valign="top" align="right"
style="border-left: medium none; border-right: medium none;
border-top: medium double; border-bottom: medium none"><strong>< %=

sTotal1 %></strong>
<%
End IF
End IF
lcnt = lcnt + 1
Next
%>
</td>
</tr>
<%
End IF
Session.Add("rp tend", Timer())
Session.Add("rp ttime", FormatNumber(CD bl(Session("rpt end")) -
CDbl(Session("r ptstart")), 1))
rstemp.Close()
rstemp = Nothing
conntemp.Close( )
conntemp = Nothing
%>

</table>
<p><small><%
Response.Write( "The report ran in " & Session("rpttim e") & "

second(s)")
%>
</small></td>
</tr>
</table>


"John Saunders" <jo************ **@notcoldmail. com> wrote in message
news:ub******** ******@TK2MSFTN GP11.phx.gbl...
> <me@privacy.net > wrote in message
> news:Ow******** ******@tk2msftn gp13.phx.gbl...
> > Source Error:
> >
> > Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value > > Line 174: End IF
> > Line 175: If (sData(rownumbe r, 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, and I am trying to return
a
> date
> > field, which is calculated MAX(j5_org.invo ice_date). The item

hasn't
> > shipped, so it doesn't return a shipped date.
> >
> > How can I get this code resolved to where it doesn't blow up on

this? > >
> > This code runs in traditional ASP, but does not run in ASP.NET,

because
of
> > the error above.
>
> Could you show us where you're getting WhatCol from?
>
> A lot of things run in VBScript that don't run in VB.NET. That's because > VBScript allowed developers to get away with murder. If you really

want
to
> improve your coding, turn Options Strict On. You'll find many places

where
> VB.NET was trying to "guess the right thing".
> --
> John Saunders
> johnwsaundersii i at hotmail
>
>



Nov 18 '05 #8

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

Similar topics

5
2058
by: Fabio Fracassi | last post by:
Hi, I belive what i am trying to do is not possible, but I hope someone can change my mind. Here is some code i'd like to write: template <class type> class engine1 {}; template <class type> class engine2 {};
6
5443
by: tshad | last post by:
The error I am getting is: ******************************************************************* Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid. Source Error: Line 144: firstName.text = ClientReader("firstName") Line 145: lastName.text = ClientReader("lastName")
2
2427
by: ibiza | last post by:
Hi all, I'm using a business logic layer as described in this source code : http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src&file=GridViewObject_cs\App_Code\AuthorsComponent.cs&lang=C%23+Source It works very well until I encountered a small problem recently. When it is time to bind the data from the db to my class representing an "author" (let's say, for simplicity), what about if my row...
2
7034
by: Chris | last post by:
Hi again, I want to read all the records of a table with 2 fields. The problem is that some records have null value in the second field. This code below works when all records have both fields fiilled, but gives the error: "Conversion from type 'DBNull' to type 'String' is not valid" when not. ..... comd = New System.Data.OleDb.OleDbCommand("select name,lok from pc",
10
1902
by: marc | last post by:
Hoi there, I am a Delphi Programer who moved over to C# some months ago. So far I am really happy with C# and feelt myself confortable quite fast. Just some advanced questions regarding the type system are left. One question is the "type of type" issue: In Delphi (Pascal) I was able to do the following (free translation to C# pseudocode ;-) ):
4
6284
by: Michel Vanderbeke | last post by:
Hello, When reading data from a SqlClient.SqlDataReader in VB.NET 2005, I want to display fiels that sometimes are empty. sUser = CStr(rdUser("Name") & Space(1) & CStr(rdUser("First_Name") When the First_Name of a user is empty, I get an error telling me type DBNull cannot be converted to String. Is there a way of solving this problem?
1
6936
by: veer | last post by:
Hi i am using the follwoing code to access the data from one mdb table into other untill the field indnt =0 ot D it works fine but when empty field ("INDNT") it show the error "Operator '=' is not defined for type 'DBNull' and string "0" Do Until CrRecset.Fields("INDNT").Value = "0" Or CrRecset.Fields("INDNT").Value = "D" Udac1 = CrRecset.Fields("UDACCD").Value Indt1 = CrRecset.Fields("INDNT").Value RecId =...
3
3244
by: Sep410 | last post by:
Hi all, Please help me in this code: txtLastNameFM.Text = IIf(dgFamilyMember.CurrentRow.Cells(3).Equals(System.DBNull.Value), "", dgFamilyMember.CurrentRow.Cells(3).Value) this is an error I get: Conversion from type 'DBNull' to type 'String' is not valid. I know the value of the dgFamilyMember.CurrentRow.Cells(3).Value= null but the first part of the iif returns false! What is wrong here?
1
5479
by: Sep410 | last post by:
Hello, Here is the code that I have : If Not Val(dgFamilyMember.Rows(i).Cells(15).Value).Equals(Val(publicFamilyMemebrDS.Tables(0).Rows(i).Item(15).ToString)) Then StrFMCommet &= " FM Group: " & publicFamilyMemebrDS.Tables(0).Rows(i).Item(14).ToString & "" StrFMCommet &= " Changed to " & dgFamilyMember.Rows(i).Cells(14).Value & " *** " If flagClientDetailFMUpdated = False...
0
8830
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
9541
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
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
6074
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.