none
label.text remains RRS feed

  • Question

  • in my editCustomer Webpage(aspx) ,when i enter accountno in textbox ,if exists it displays in label.text format (Account exist) and again if i enter some account number- displays does not exist, again if i enter another account number displays the data but the label text shown remains("does not exist")

    wht should i write............

    sample code:
    DataSet ds = new DataSet();

            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = sql;
            SqlParameter Accno = new SqlParameter("@AccountNo", SqlDbType.Int);
            Accno.Value = Convert.ToInt32(AccountNumberTextBox.Text);
            cmd.Parameters.Add(Accno);
            Accno.Direction = ParameterDirection.Input;

            da.SelectCommand = cmd;
            da.Fill(ds);

            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                       
                        CustomerIDTextBox.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString();
                        AccountTypeDropDownList.SelectedValue = ds.Tables[0].Rows[0]["AccountType"].ToString();
                        DtopenTxtbox.Text = ds.Tables[0].Rows[0]["DateofOpening"].ToString();
                        CurrentAmountTextBox.Text = ds.Tables[0].Rows[0]["CurrentAmount"].ToString();
                        StatusRadioButonLst.SelectedValue = ds.Tables[0].Rows[0]["Status"].ToString();
                      
                    }
                    else
                    {
                        SucessLabel.Text= "Account No does not exist";
                    }
                }
    Friday, November 13, 2009 7:03 AM

Answers

  • Well, that is just the other way around. When rows < 0, make sure you change the other labels if the IF statement is false.

    Since you are changing some labels if there are rows and others if there are no rows then the code will of course not reach that section of code.
    So you need (in this case) change all labels in case there are rows or not in order to reflect this.
    Otherwise the old values will be remain until the the Rows.Count > 0 evaluates to TRUE.


                    if (ds.Tables[0].Rows.Count > 0)
                    {
                       Texbox1.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString();
                       SucessLabel.Text= "";
                    }
                    else
                    {
                       Texbox1.Text = "";
                       SucessLabel.Text= "Customer not found";
                    }
    This posting is provided "AS IS" with no warranties.
    • Marked as answer by Yichun_Feng Tuesday, November 17, 2009 9:14 AM
    Friday, November 13, 2009 9:37 AM

All replies

  • As far as I can see you do not change the label when rows > 0, make sure you change Sucesslabel if the IF statement is true.

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                       
                        CustomerIDTextBox.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString();
                        AccountTypeDropDownList.SelectedValue = ds.Tables[0].Rows[0]["AccountType"].ToString();
                        DtopenTxtbox.Text = ds.Tables[0].Rows[0]["DateofOpening"].ToString();
                        CurrentAmountTextBox.Text = ds.Tables[0].Rows[0]["CurrentAmount"].ToString();
                        StatusRadioButonLst.SelectedValue = ds.Tables[0].Rows[0]["Status"].ToString();

                        SucessLabel.Text= ""; 
                        // or
                        // SucessLabel.Text= "Some other text";
     
                    }
                    else
                    {
                        SucessLabel.Text= "Account No does not exist";
                    }

    HTH
    //Michael


    This posting is provided "AS IS" with no warranties.
    Friday, November 13, 2009 8:09 AM
  • what i mean to say...
    for example...if i enter accountnumber all the details regarding to tht details like name,amount etc  it displays in textbox,but if i give incorrect accountno,previous details stores in textbox with tht it gives error message(account no does not exist)

    wht should i do for that?
    Friday, November 13, 2009 9:11 AM
  • Well, that is just the other way around. When rows < 0, make sure you change the other labels if the IF statement is false.

    Since you are changing some labels if there are rows and others if there are no rows then the code will of course not reach that section of code.
    So you need (in this case) change all labels in case there are rows or not in order to reflect this.
    Otherwise the old values will be remain until the the Rows.Count > 0 evaluates to TRUE.


                    if (ds.Tables[0].Rows.Count > 0)
                    {
                       Texbox1.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString();
                       SucessLabel.Text= "";
                    }
                    else
                    {
                       Texbox1.Text = "";
                       SucessLabel.Text= "Customer not found";
                    }
    This posting is provided "AS IS" with no warranties.
    • Marked as answer by Yichun_Feng Tuesday, November 17, 2009 9:14 AM
    Friday, November 13, 2009 9:37 AM
  • thanks!!!!!!!!!!!
    Friday, November 13, 2009 9:46 AM