datareader.getstring(0) error

N

Nakhi

Hi,
my code is very simple.

dim cm as oledbcommand= new oledbcommand("select * from page " ,cn)
cn.open()
Dim dr As OleDbDataReader = cm.ExecuteReader()
dim cate=dr.getstring(1) 'error line"
label1.text=cate

but there is error for dr.getstring(1), the error reads:the data of this
column does not exist:
I am sure the second line exist(not null) and is string type.

when add a read() before the error line,then there is no error. And in
another sub, I can output the same datareader content using a do while
read() function.

Can anyone give me a hint?

Nakhi
From Lijinag,China.
 
R

Ravikanth[MVP]

Hi
Try with the following code:

RULE: Always call Read before accessing data.

myReader = myCommand.ExecuteReader();
// Always call Read before accessing data.
while (myReader.Read()) {
Console.WriteLine(myReader.GetInt32(0) + ", " +
myReader.GetString(1));
}


HTH
Ravikanth
 
N

Natty Gur

Hi,

you must use Read() in order to populate the reader.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
N

Nakhi

thanx,it works, that is move the cursor to the first line.

Nakhi
Lijiang,Yunnan,China,Asia.
 

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,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top