Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. datareader in asp.net using c#

datareader in asp.net using c#

Scheduled Pinned Locked Moved C#
csharpdatabasehelpasp-netquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HowRU
    wrote on last edited by
    #1

    Hi All, Can anybody help me?.... I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok... I am getting the correct output using a datareader for the datagrid ....as.... DGShow.DataSource=dread; DGShow.DataBind(); ...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message.... Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. the code is...... while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } as i am not sure that i m on right track please help me.. thanks

    M D 2 Replies Last reply
    0
    • H HowRU

      Hi All, Can anybody help me?.... I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok... I am getting the correct output using a datareader for the datagrid ....as.... DGShow.DataSource=dread; DGShow.DataBind(); ...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message.... Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. the code is...... while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } as i am not sure that i m on right track please help me.. thanks

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      DataReader gives you a forwatd only reading. So once you go to the end of it ,you can't return to first row again. Mazy
      "One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji

      1 Reply Last reply
      0
      • H HowRU

        Hi All, Can anybody help me?.... I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok... I am getting the correct output using a datareader for the datagrid ....as.... DGShow.DataSource=dread; DGShow.DataBind(); ...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message.... Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. the code is...... while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } as i am not sure that i m on right track please help me.. thanks

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You can't use a datareader as your datasource if your binding more than one control to it. You would have to bind them to a datatable in a dataset... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups