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. How to get the values into the textbox using datareader in asp.net

How to get the values into the textbox using datareader in asp.net

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-netcomhelp
4 Posts 4 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.
  • A Offline
    A Offline
    Anjani Poornima
    wrote on last edited by
    #1

    hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)

    S A S 3 Replies Last reply
    0
    • A Anjani Poornima

      hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)

      S Offline
      S Offline
      Sujay chakraborty
      wrote on last edited by
      #2

      There could be few issues that u need to resolve for this code. Firstly if you are having multiple rows in your database and you are trying to fetch those values in a single text box using DataReader then only the last record would be visible to you as the TextBox will be set to the last value only..... Secondly for using DataReader and SqlCommand you need an open connection so you need to specify an sqlconnection object and put it like

      SqlConnection con = new SqlConnection();
      con.Open();
      sqlcommand com=new sqlcommand(query,con);
      DataReader dr=com.ExecuteReader();
      while(rdr.read())
      {
      textbox.text=rdr["fieldname"].getstring();
      }
      con.Close();

      As DataReader is readonly and forward only so only the last value is available to the TextBox control. To avoid that and to retrieve all the values try some listbox or combobox. Best of luck!!! Try hard but don't get stubborn

      1 Reply Last reply
      0
      • A Anjani Poornima

        hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        As you are new in .Net World,I will suggest you to buy some Beginners Book and start reading yourself. Which will help you learn better. :) Good Luck !

        cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net

        1 Reply Last reply
        0
        • A Anjani Poornima

          hi, i am very new to this .net world. I like to get the values from the database into the textbox using datareader. I tried in this way : sqlcommand com=new sqlcommand(query,connectionstring); datareader rdr=com.executereader(); while(rdr.read()) { textbox.text=rdr["fieldname"].getstring(); } But i failed to get the values plz help me....in getting the values into the textbox using datareader plz post the codesnippet how to do it Thanx in advance :)

          S Offline
          S Offline
          SayreCC
          wrote on last edited by
          #4

          Hi, try this textbox1.text = rdr["fieldname"].tostring();

          Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.

          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