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. fill a textbox from a dataset

fill a textbox from a dataset

Scheduled Pinned Locked Moved C#
databasehelpquestion
8 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.
  • K Offline
    K Offline
    krisman
    wrote on last edited by
    #1

    Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman

    G E 2 Replies Last reply
    0
    • K krisman

      Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman

      G Offline
      G Offline
      Guinness4Strength
      wrote on last edited by
      #2

      try this DataSet dSet = new DataSet; ///fill DataSet here if(dSet.Tables["YourTable"].Rows.Count >0) TextBox.Text=dSet.Tables["YourTable"].Rows[0]["YouFieldName"].ToString();

      K 1 Reply Last reply
      0
      • G Guinness4Strength

        try this DataSet dSet = new DataSet; ///fill DataSet here if(dSet.Tables["YourTable"].Rows.Count >0) TextBox.Text=dSet.Tables["YourTable"].Rows[0]["YouFieldName"].ToString();

        K Offline
        K Offline
        krisman
        wrote on last edited by
        #3

        Not quite getting result I thought, but at least there is a result! I'll do some more tinkering. Thanks! Krisman

        P 1 Reply Last reply
        0
        • K krisman

          Not quite getting result I thought, but at least there is a result! I'll do some more tinkering. Thanks! Krisman

          P Offline
          P Offline
          partyganger
          wrote on last edited by
          #4

          Or try using a Convert.ToString() around your DataSet result. Somehow ToString sometimes returns the Class name, i.e. DataColumn

          1 Reply Last reply
          0
          • K krisman

            Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman

            E Offline
            E Offline
            Edbert P
            wrote on last edited by
            #5

            You can't just call DataBind() and expect .NET to solve everything for you. You need to specify to which property of the textbox you want to bind the data to, and the table and column in the dataset. Here's an example to bind the data to textbox's text property: this.txtAddrUrbnCmtyID.DataBindings.Add(new Binding("Text", ds, "tableName.columnName")); For more information, check the MSDN site for Binding Class[^]. Edbert P. Sydney, Australia.

            K 1 Reply Last reply
            0
            • E Edbert P

              You can't just call DataBind() and expect .NET to solve everything for you. You need to specify to which property of the textbox you want to bind the data to, and the table and column in the dataset. Here's an example to bind the data to textbox's text property: this.txtAddrUrbnCmtyID.DataBindings.Add(new Binding("Text", ds, "tableName.columnName")); For more information, check the MSDN site for Binding Class[^]. Edbert P. Sydney, Australia.

              K Offline
              K Offline
              krisman
              wrote on last edited by
              #6

              This will only work in a Windows Form, I've learned that much. I'm building WebForms, so I have to come up with different round-about ways to do things. Microsoft has never been known for being user and/or developer friendly. Krisman

              E 1 Reply Last reply
              0
              • K krisman

                This will only work in a Windows Form, I've learned that much. I'm building WebForms, so I have to come up with different round-about ways to do things. Microsoft has never been known for being user and/or developer friendly. Krisman

                E Offline
                E Offline
                Edbert P
                wrote on last edited by
                #7

                I doubt that, because I have used data binding in my web project. Here's an excerpt of the code that I used:

                cbApplication.DataSource = dsApplication.Tables(0)
                cbApplication.DataTextField = "DirectoryName"
                cbApplication.DataValueField = "IDDirectory"
                cbApplication.DataBind()

                Edbert P. Sydney, Australia.

                K 1 Reply Last reply
                0
                • E Edbert P

                  I doubt that, because I have used data binding in my web project. Here's an excerpt of the code that I used:

                  cbApplication.DataSource = dsApplication.Tables(0)
                  cbApplication.DataTextField = "DirectoryName"
                  cbApplication.DataValueField = "IDDirectory"
                  cbApplication.DataBind()

                  Edbert P. Sydney, Australia.

                  K Offline
                  K Offline
                  krisman
                  wrote on last edited by
                  #8

                  I'll have to try again. But I keep getting errors and our .Net gurus where I work (our network guys) said it's because I'm trying to use a Windows Forms functionality with a Web Form. But I'm also working without a Localhost because of the way .Net was installed on our systems and servers. Krisman

                  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