datareader.getstring(0) error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nakhi

    #1

    datareader.getstring(0) error

    Hi,
    my code is very simple.

    dim cm as oledbcommand= new oledbcommand("s elect * from page " ,cn)
    cn.open()
    Dim dr As OleDbDataReader = cm.ExecuteReade r()
    dim cate=dr.getstri ng(1) 'error line"
    label1.text=cat e

    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]

    #2
    datareader.gets tring(0) error

    Hi
    Try with the following code:

    RULE: Always call Read before accessing data.

    myReader = myCommand.Execu teReader();
    // Always call Read before accessing data.
    while (myReader.Read( )) {
    Console.WriteLi ne(myReader.Get Int32(0) + ", " +
    myReader.GetStr ing(1));
    }


    HTH
    Ravikanth
    [color=blue]
    >-----Original Message-----
    >Hi,
    >my code is very simple.
    >
    >dim cm as oledbcommand= new oledbcommand("s elect * from[/color]
    page " ,cn)[color=blue]
    > cn.open()
    > Dim dr As OleDbDataReader = cm.ExecuteReade r()
    > dim cate=dr.getstri ng(1) 'error line"
    > label1.text=cat e
    >
    >but there is error for dr.getstring(1) , the error[/color]
    reads:the data of this[color=blue]
    >column does not exist:
    >I am sure the second line exist(not null) and is string[/color]
    type.[color=blue]
    >
    >when add a read() before the error line,then there is[/color]
    no error. And in[color=blue]
    >another sub, I can output the same datareader content[/color]
    using a do while[color=blue]
    >read() function.
    >
    >Can anyone give me a hint?
    >
    >Nakhi
    >From Lijinag,China.
    >
    >
    >.
    >[/color]

    Comment

    • Ravikanth[MVP]

      #3
      datareader.gets tring(0) error

      Hi
      Try with the following code:

      RULE: Always call Read before accessing data.

      myReader = myCommand.Execu teReader();
      // Always call Read before accessing data.
      while (myReader.Read( )) {
      Console.WriteLi ne(myReader.Get Int32(0) + ", " +
      myReader.GetStr ing(1));
      }


      HTH
      Ravikanth
      [color=blue]
      >-----Original Message-----
      >Hi,
      >my code is very simple.
      >
      >dim cm as oledbcommand= new oledbcommand("s elect * from[/color]
      page " ,cn)[color=blue]
      > cn.open()
      > Dim dr As OleDbDataReader = cm.ExecuteReade r()
      > dim cate=dr.getstri ng(1) 'error line"
      > label1.text=cat e
      >
      >but there is error for dr.getstring(1) , the error[/color]
      reads:the data of this[color=blue]
      >column does not exist:
      >I am sure the second line exist(not null) and is string[/color]
      type.[color=blue]
      >
      >when add a read() before the error line,then there is[/color]
      no error. And in[color=blue]
      >another sub, I can output the same datareader content[/color]
      using a do while[color=blue]
      >read() function.
      >
      >Can anyone give me a hint?
      >
      >Nakhi
      >From Lijinag,China.
      >
      >
      >.
      >[/color]

      Comment

      • Natty Gur

        #4
        Re: datareader.gets tring(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 http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Natty Gur

          #5
          Re: datareader.gets tring(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 http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Nakhi

            #6
            Re: datareader.gets tring(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.19 12@tk2msftngp13 .phx.gbl...[color=blue]
            > 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 http://www.developersdex.com ***
            > Don't just participate in USENET...get rewarded for it![/color]


            Comment

            • Nakhi

              #7
              Re: datareader.gets tring(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.19 12@tk2msftngp13 .phx.gbl...[color=blue]
              > 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 http://www.developersdex.com ***
              > Don't just participate in USENET...get rewarded for it![/color]


              Comment

              Working...