datareader.getstring(0) error

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default datareader.getstring(0) error

    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.


    Nakhi Guest

  2. Similar Questions and Discussions

    1. opengl: What happened to GetString?
      hi, on ruby173 and previous this worked: GL.GetString( GL::VERSION) but with 180-10 i am getting this error message: :in `GetString': NULL...
    2. encoder.GetString() help
      I have tried the following to convert an encrypted byte() into a string to write it to a database: Dim encoding as new UTF8Encoding() Dim EncNum...
    3. inserting option values into drop down lists with getstring when using distinct in the SQL
      I don't know what your problem is. It works fine for me. Here is my code: <% dim cn,rs set cn=server.CreateObject("adodb.connection") ...
    4. getstring really slow
      Hi, Hope somebody can help because i've looked everywhere else fo ran answer. I'm connecting to an Access table with 100+ rows of data of approx...
    5. can't getstring & display datareader
      Hi, I want to display a single record datareader and get a value from it. But I can't do both together. After "dim dr as...
  3. #2

    Default datareader.getstring(0) error

    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
    >-----Original Message-----
    >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.
    >
    >
    >.
    >
    Ravikanth[MVP] Guest

  4. #3

    Default Re: datareader.getstring(0) error

    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


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  5. #4

    Default Re: datareader.getstring(0) error

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

    Nakhi
    Lijiang,Yunnan,China,Asia.


    "Natty Gur" <natty@dao2com.com> дÈëÏûÏ¢ÐÂÎÅ
    :OvLkJvgSDHA.1912@tk2msftngp13.phx.gbl...
    > 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
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Nakhi Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139