473,396 Members | 1,895 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.

What's wrong???

Can someone please tell me what is wrong with the following code!

I have a record in the datareader but it isn't showing up and niether is the
label... I presume there is a problem with this code!

Thanks

...CODE..
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
While myReader.Read()
hasRows = True
If hasRows = True Then
DGPages.DataBind()
ElseIf hasRows = False Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If
End While

myReader.Close()

Nov 19 '05 #1
5 1184
Hi,

I never really tested this, but my guess would be as follows:
Since DataReaders are forward only, your call to DataReader.Read is moving
the reader cursor forward, then
when you call the DataBind method it will also cause the DataGrid to move
through the same reader, which has already moved on to the next record. In
your case there is no next record so the DataGrid is empty.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:14**********************************@microsof t.com...
Can someone please tell me what is wrong with the following code!

I have a record in the datareader but it isn't showing up and niether is the label... I presume there is a problem with this code!

Thanks

..CODE..
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
While myReader.Read()
hasRows = True
If hasRows = True Then
DGPages.DataBind()
ElseIf hasRows = False Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If
End While

myReader.Close()

Nov 19 '05 #2
OK... Got it and I think you are right but any ideas on how to get around
this issue???

Thanks
"Chris Taylor" wrote:
Hi,

I never really tested this, but my guess would be as follows:
Since DataReaders are forward only, your call to DataReader.Read is moving
the reader cursor forward, then
when you call the DataBind method it will also cause the DataGrid to move
through the same reader, which has already moved on to the next record. In
your case there is no next record so the DataGrid is empty.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:14**********************************@microsof t.com...
Can someone please tell me what is wrong with the following code!

I have a record in the datareader but it isn't showing up and niether is

the
label... I presume there is a problem with this code!

Thanks

..CODE..
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
While myReader.Read()
hasRows = True
If hasRows = True Then
DGPages.DataBind()
ElseIf hasRows = False Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If
End While

myReader.Close()


Nov 19 '05 #3
This is just a guess because I don't write VB

Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
DGPages.DataBind()

If DGPages.Rows.Count = 0 Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If

myReader.Close()
Nov 19 '05 #4
Chris is right, what you're doing is binding the datagrid repeatedly to the
datareader. For every row of the datareader you are calling the databind
method, thus constantly updating the grid. You don't have to ever call the
read method when you are binding directly to the datareader. If you're using
ASP.Net 1.1, There is already a HasRows property for the datareader that you
can check and avoid the other steps alltogether. Just check the hasrows
property of the datareader then bind if true. Just don't call the read
method before binding as that will read the first row.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:14**********************************@microsof t.com...
Can someone please tell me what is wrong with the following code!

I have a record in the datareader but it isn't showing up and niether is
the
label... I presume there is a problem with this code!

Thanks

..CODE..
Dim myReader As SqlDataReader = cmd.ExecuteReader()
Dim hasRows As Boolean
hasRows = False
DGPages.DataSource = myReader
While myReader.Read()
hasRows = True
If hasRows = True Then
DGPages.DataBind()
ElseIf hasRows = False Then
lblNoContent.Visible = True
lblNoContent.Text = "There a currently no pages for"
End If
End While

myReader.Close()

Nov 19 '05 #5
Thanks boys!

Nov 19 '05 #6

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
56
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.