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

logic check please - not getting results wanted from IF

(still a .NET newbie)

I have a chunk of code in a Page_Load routine that pulls data from a SQL
Server table. The Select statement looks for any "events" scheduled for
today. Then my IF statement writes some HTML to a asp:label tag and
conditionally fills it with HTML based upon any records were found. Seems
simple huh? It works fine if the recordset is null...or in .NET speak, if
the If Not DataReader.Read()..but when data IS found....nothing happens.
All it writes to the page is literally "<ul></ul>". D'oh!

Could someone spot check this please? It seems fine to me......
'==================================
'Display any events happening today....

Dim strTodayEventsSQL As String
Dim datTodayEvents As SQLDataReader

strHTML = ""
strTodayEventsSQL = "SELECT * FROM IntranetCalendar WHERE CalMonth = " &
Month(Today()) & " AND CalDay = " & Day(Today()) & " AND CalYear = " &
Year(Today()) & " AND Display = 1;"

cmdSQLCommand = New SQLCommand(strTodayEventsSQL, objDbConn)
datTodayEvents = cmdSQLCommand.ExecuteReader()

strHTML = strHTML & "<ul>"

If datTodayEvents.Read() Then

'****NOTHING SEEMS TO HAPPEN HERE*********
While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle") &
"</a></li>"
End While

Else
strHTML = strHTML & "<li><a href=" & CHR(34) & "calendar/default.aspx"
& CHR(34) & ">There is nothing entered in for today - however, you can add
agency related events to the DRPT Calendar here.</a></li>"
End If

strHTML = strHTML & "</ul>"

lblTodayEvents.Text = strHTML

datTodayEvents.Close()
'==================================
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #1
3 1101
Hello Shane
Get rid of the "If datTodayEvents.Read()"
just use

strHtml=""

While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle")
&
"</a></li>"
End While

If strHtml.Length <1 Then
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx"
& CHR(34) & ">There is nothing entered in for today - however, you
can add
agency related events to the DRPT Calendar here.</a></li>"
End If
The way you are doing it you are throwing away the first row. If your test
situation has only one row returned, you will never get that row doing it
the way you where doing it.

also you should change your concatination to:

strHTML += "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle")
&
"</a></li>"

Old habits die hard :-)

--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================


"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
(still a .NET newbie)

I have a chunk of code in a Page_Load routine that pulls data from a SQL
Server table. The Select statement looks for any "events" scheduled for
today. Then my IF statement writes some HTML to a asp:label tag and
conditionally fills it with HTML based upon any records were found. Seems
simple huh? It works fine if the recordset is null...or in .NET speak, if
the If Not DataReader.Read()..but when data IS found....nothing happens.
All it writes to the page is literally "<ul></ul>". D'oh!

Could someone spot check this please? It seems fine to me......
'==================================
'Display any events happening today....

Dim strTodayEventsSQL As String
Dim datTodayEvents As SQLDataReader

strHTML = ""
strTodayEventsSQL = "SELECT * FROM IntranetCalendar WHERE CalMonth = " &
Month(Today()) & " AND CalDay = " & Day(Today()) & " AND CalYear = " &
Year(Today()) & " AND Display = 1;"

cmdSQLCommand = New SQLCommand(strTodayEventsSQL, objDbConn)
datTodayEvents = cmdSQLCommand.ExecuteReader()

strHTML = strHTML & "<ul>"

If datTodayEvents.Read() Then

'****NOTHING SEEMS TO HAPPEN HERE*********
While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle") &
"</a></li>"
End While

Else
strHTML = strHTML & "<li><a href=" & CHR(34) & "calendar/default.aspx" & CHR(34) & ">There is nothing entered in for today - however, you can add
agency related events to the DRPT Calendar here.</a></li>"
End If

strHTML = strHTML & "</ul>"

lblTodayEvents.Text = strHTML

datTodayEvents.Close()
'==================================
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #2
Do you just have 1 record to display ?
If datTodayEvents.Read() Then This puts you in the first record.
While datTodayEvents.Read()
This puts you in the second record.

If there is no second record then your strHTML will be
empty.
Thanks,
Shan
-----Original Message-----
(still a .NET newbie)

I have a chunk of code in a Page_Load routine that pulls data from a SQLServer table. The Select statement looks for any "events" scheduled fortoday. Then my IF statement writes some HTML to a asp:label tag andconditionally fills it with HTML based upon any records were found. Seemssimple huh? It works fine if the recordset is null...or in .NET speak, ifthe If Not DataReader.Read()..but when data IS found....nothing happens.All it writes to the page is literally "<ul></ul>". D'oh!

Could someone spot check this please? It seems fine to me......

'==================================
'Display any events happening today....

Dim strTodayEventsSQL As String
Dim datTodayEvents As SQLDataReader

strHTML = ""
strTodayEventsSQL = "SELECT * FROM IntranetCalendar WHERE CalMonth = " &Month(Today()) & " AND CalDay = " & Day(Today()) & " AND CalYear = " &Year(Today()) & " AND Display = 1;"

cmdSQLCommand = New SQLCommand(strTodayEventsSQL, objDbConn)datTodayEvents = cmdSQLCommand.ExecuteReader()

strHTML = strHTML & "<ul>"

If datTodayEvents.Read() Then

'****NOTHING SEEMS TO HAPPEN HERE*********
While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents ("CalTitle") &"</a></li>"
End While

Else
strHTML = strHTML & "<li><a href=" & CHR(34) & "calendar/default.aspx"& CHR(34) & ">There is nothing entered in for today - however, you can addagency related events to the DRPT Calendar here.</a></li>"
End If

strHTML = strHTML & "</ul>"

lblTodayEvents.Text = strHTML

datTodayEvents.Close()
'==================================
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

.

Nov 18 '05 #3
That was it. Thanks!

--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"IbrahimMalluf" <Ib*****@malluf.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
Hello Shane
Get rid of the "If datTodayEvents.Read()"
just use

strHtml=""

While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle") &
"</a></li>"
End While

If strHtml.Length <1 Then
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx"
& CHR(34) & ">There is nothing entered in for today - however, you
can add
agency related events to the DRPT Calendar here.</a></li>"
End If
The way you are doing it you are throwing away the first row. If your test
situation has only one row returned, you will never get that row doing it
the way you where doing it.

also you should change your concatination to:

strHTML += "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle") &
"</a></li>"

Old habits die hard :-)

--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================


"D. Shane Fowlkes" <sh**********@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
(still a .NET newbie)

I have a chunk of code in a Page_Load routine that pulls data from a SQL
Server table. The Select statement looks for any "events" scheduled for
today. Then my IF statement writes some HTML to a asp:label tag and
conditionally fills it with HTML based upon any records were found. Seems simple huh? It works fine if the recordset is null...or in .NET speak, if the If Not DataReader.Read()..but when data IS found....nothing happens.
All it writes to the page is literally "<ul></ul>". D'oh!

Could someone spot check this please? It seems fine to me......
'==================================
'Display any events happening today....

Dim strTodayEventsSQL As String
Dim datTodayEvents As SQLDataReader

strHTML = ""
strTodayEventsSQL = "SELECT * FROM IntranetCalendar WHERE CalMonth = " &
Month(Today()) & " AND CalDay = " & Day(Today()) & " AND CalYear = " &
Year(Today()) & " AND Display = 1;"

cmdSQLCommand = New SQLCommand(strTodayEventsSQL, objDbConn)
datTodayEvents = cmdSQLCommand.ExecuteReader()

strHTML = strHTML & "<ul>"

If datTodayEvents.Read() Then

'****NOTHING SEEMS TO HAPPEN HERE*********
While datTodayEvents.Read()
strHTML = strHTML & "<li><a href=" & CHR(34) &
"calendar/default.aspx" & CHR(34) & ">" & datTodayEvents("CalTitle") &
"</a></li>"
End While

Else
strHTML = strHTML & "<li><a href=" & CHR(34) &

"calendar/default.aspx"
& CHR(34) & ">There is nothing entered in for today - however, you can add agency related events to the DRPT Calendar here.</a></li>"
End If

strHTML = strHTML & "</ul>"

lblTodayEvents.Text = strHTML

datTodayEvents.Close()
'==================================
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************


Nov 18 '05 #4

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

Similar topics

2
by: Steve Jorgensen | last post by:
Hi all, In the code I'm working on to learn Java, I wanted to check to see if a string can be converted to a BigDecimal, and get the BigDecimal value if so. There is no assumption that the...
5
by: John | last post by:
Hi, In a nutshell, why am I getting the results I am getting? I would have expected a call to method1( n) to return an 'n' length string. At first I thought it was a problem in my function,...
7
by: David Shorthouse | last post by:
I am attempting to create a "new account creation" asp, but would ideally like the routine to check the Access db for an existing email address and username (called UID below). The select query...
22
by: James H. | last post by:
Greetings! I'm new to Python and am struggling a little with "and" and "or" logic in Python. Since Python always ends up returning a value and this is a little different from C, the language I...
3
by: Rob Meade | last post by:
Hi all, I have some code which I cobbled together from some examples online, so its probably wrong, although I did have it working a little while ago, unfortunately for some reason it seems to...
1
by: Vaibhav Modak | last post by:
Hi All, I have a Web Service written in Java (Web Logic) and I am trying to call it in my ASP. NET client. I am facing a problem while getting the data from the Web Service Method. My Web...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
3
by: Geoff Cox | last post by:
Hello, I am not getting the logic right here... I want to send to a php file the results of clicking some buttons but only when an email address has been added, so function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.