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. Need help populating fields from database to form in page load

Need help populating fields from database to form in page load

Scheduled Pinned Locked Moved ASP.NET
databasedesignsaleshelp
2 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.
  • B Offline
    B Offline
    Bootzilla33
    wrote on last edited by
    #1

    I am trying to populate the fields on a form from the database and the values aren't populating on the form. I have the value for the where clause hard coded in the code and it doesn't show the values that are in the database for that record on the form:

    protected void Page_Load(object sender, EventArgs e)
    {
    this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;

            {
                labelRID.Text = Request.QueryString\["id"\];
                
                string rid = labelRID.Text;
                string activityid = labelactivityid.Text;
    
                if (!IsPostBack)
                {
                    Bindactivitycodedropdown();
    
    
                    if (rid != "")
                    {
    
                        OracleConnection conn = new OracleConnection();
                        OracleCommand cmd = new OracleCommand();
                        conn.ConnectionString = strConnection;
                        conn.Open();
    
                        cmd.Connection = conn;
                        cmd.CommandText = "Select RID, BUYING\_ACTIVITY\_ID, CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE from BUYING\_ACTIVITY WHERE RID = '55555'";
                        cmd.Parameters.Add(new OracleParameter("RID", Request.QueryString\["ID"\]));
                        OracleDataAdapter da = new OracleDataAdapter(cmd);
                        cmd.CommandType = CommandType.Text;
                        OracleDataReader dr = cmd.ExecuteReader();
    
                        if (dr.Read())
                        {
                            labelRID.Text = dr\["rid"\].ToString();
                            custname.Text = dr\["customer\_name"\].ToString();
                            custcity.Text = dr\["customer\_city"\].ToString();
                            custstate.Text = dr\["customer\_state"\].ToString();
                            custpostalcode.Text = dr\["customer\_postal\_code"\].ToString();
                            activitycode.SelectedItem.Text = dr\["buying\_activity\_code"\].ToString();
                            custsrccode.Text = dr\["customer\_source\_code"\].ToString();
                            cvactivitycode.Enabled = false;
                            //custname.Text = custstate.SelectedValue.ToString();
    
                            //if (activitycode.SelectedValue == "0")
                            //{
                            //    cu
    
    Richard DeemingR 1 Reply Last reply
    0
    • B Bootzilla33

      I am trying to populate the fields on a form from the database and the values aren't populating on the form. I have the value for the where clause hard coded in the code and it doesn't show the values that are in the database for that record on the form:

      protected void Page_Load(object sender, EventArgs e)
      {
      this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;

              {
                  labelRID.Text = Request.QueryString\["id"\];
                  
                  string rid = labelRID.Text;
                  string activityid = labelactivityid.Text;
      
                  if (!IsPostBack)
                  {
                      Bindactivitycodedropdown();
      
      
                      if (rid != "")
                      {
      
                          OracleConnection conn = new OracleConnection();
                          OracleCommand cmd = new OracleCommand();
                          conn.ConnectionString = strConnection;
                          conn.Open();
      
                          cmd.Connection = conn;
                          cmd.CommandText = "Select RID, BUYING\_ACTIVITY\_ID, CUSTOMER\_SOURCE\_CODE, CUSTOMER\_NAME, CUSTOMER\_CITY, CUSTOMER\_STATE, CUSTOMER\_POSTAL\_CODE, BUYING\_ACTIVITY\_CODE from BUYING\_ACTIVITY WHERE RID = '55555'";
                          cmd.Parameters.Add(new OracleParameter("RID", Request.QueryString\["ID"\]));
                          OracleDataAdapter da = new OracleDataAdapter(cmd);
                          cmd.CommandType = CommandType.Text;
                          OracleDataReader dr = cmd.ExecuteReader();
      
                          if (dr.Read())
                          {
                              labelRID.Text = dr\["rid"\].ToString();
                              custname.Text = dr\["customer\_name"\].ToString();
                              custcity.Text = dr\["customer\_city"\].ToString();
                              custstate.Text = dr\["customer\_state"\].ToString();
                              custpostalcode.Text = dr\["customer\_postal\_code"\].ToString();
                              activitycode.SelectedItem.Text = dr\["buying\_activity\_code"\].ToString();
                              custsrccode.Text = dr\["customer\_source\_code"\].ToString();
                              cvactivitycode.Enabled = false;
                              //custname.Text = custstate.SelectedValue.ToString();
      
                              //if (activitycode.SelectedValue == "0")
                              //{
                              //    cu
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Bootzilla33 wrote:

      activitycode.SelectedItem.Text = dr["buying_activity_code"].ToString(); ... activitycode.SelectedItem.Text = "";

      You're still changing the text of the first item in the list, rather than selecting the correct item. As I keep telling you, you need to set the SelectedValue property on the list, not the Text property on the SelectedItem.

      activitycode.SelectedValue = dr["buying_activity_code"].ToString();
      ...
      activitycode.SelectedValue = "";

      If the other values are not populating, then there is no matching record in the database. If you think there is, then you're not looking at the same database as your code.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      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