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. Web Development
  3. ASP.NET
  4. datareader in asp.net using c#

datareader in asp.net using c#

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpasp-netquestion
4 Posts 2 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

    S 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

      S Offline
      S Offline
      sukesh g
      wrote on last edited by
      #2

      Hi, Once the datareader is assigned to the DGShow(datagrid) as a datasource.you cannot use the same datareader for assiging in textboxs. For this you need close the datareader and again open it and for assigning to textboxs. i will give the code below. DGShow.DataSource=dread; DGShow.DataBind(); dread.close(); dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } Regards, Sukesh.g Sukesh.g

      H 1 Reply Last reply
      0
      • S sukesh g

        Hi, Once the datareader is assigned to the DGShow(datagrid) as a datasource.you cannot use the same datareader for assiging in textboxs. For this you need close the datareader and again open it and for assigning to textboxs. i will give the code below. DGShow.DataSource=dread; DGShow.DataBind(); dread.close(); dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } Regards, Sukesh.g Sukesh.g

        H Offline
        H Offline
        HowRU
        wrote on last edited by
        #3

        Hi, In the following code the last line.... dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); //****giving error**** } ....is giving error like ////// {specified cast is not valid} as in sql database Phone field is numeric.....if i change it's datatype to decimal & that line to this.... txtphone.Text=dread.GetDecimal(3).ToString(); then it works.....so plz help me if i ve numeric or int. datatype of fields in the database...then how to read them??....which GetXXXXX() function, we will use for that... please help me... Thanks

        S 1 Reply Last reply
        0
        • H HowRU

          Hi, In the following code the last line.... dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); //****giving error**** } ....is giving error like ////// {specified cast is not valid} as in sql database Phone field is numeric.....if i change it's datatype to decimal & that line to this.... txtphone.Text=dread.GetDecimal(3).ToString(); then it works.....so plz help me if i ve numeric or int. datatype of fields in the database...then how to read them??....which GetXXXXX() function, we will use for that... please help me... Thanks

          S Offline
          S Offline
          sukesh g
          wrote on last edited by
          #4

          Hi, No problem, you can continue with this........don't worry about int or numeric data types. Go for below statement ... TextBox1.Text=dr.GetDecimal(0).ToString(); its ok.... Regards, sukesh.g Sukesh.g

          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