Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a textbox id=txtShowApartment,I need is ,get the details from dataset (a column ) and show the details in a txtShowApartment with spilt with ",",I do a code but some problem is there...

here is the code:

C#
public void GetGroupsOntxt()
      {
          DataSet dsGetGroups = new DataSet();
          string ShowApartments = string.Empty;
          try
          {
              dsGetGroups = objCustomerMessageBusinessRule.GetApartmentNumber();
              if (dsGetGroups.Tables[0].Rows.Count > 0)
               {
                 for (int Apartment = 0; Apartment < dsGetGroups.Tables[0].Rows.Count; Apartment++)
                   {

                       ShowApartments = dsGetGroups.Tables[0].Rows[Apartment]["ApartmentNumber"].ToString() + ",";
                   }
                 txtShowApartment.Text = ShowApartments.ToString();
              }
              else
              {
                  txtShowApartment.Text = string.Empty;
              }
          }
          catch (Exception ex)
          {
              EnterpriseLogger.HandleGeneralException(ex);
          }
      }
Posted
Comments
[no name] 16-Oct-12 2:56am    
where is the problem
what error it show.
AshishChaudha 16-Oct-12 3:06am    
whats the problem??

A minor problem my friend

Instead of

C#
ShowApartments = dsGetGroups.Tables[0].Rows[Apartment]["ApartmentNumber"].ToString() 


use,


C#
ShowApartments += dsGetGroups.Tables[0].Rows[Apartment]["ApartmentNumber"].ToString() 


Notice the =+ instead of =

Hope that helps. If it does mark it as solution and/or upvote.

Thanks
Milind
 
Share this answer
 
Comments
aravindnass 18-Oct-12 7:24am    
thanks ...
C#
public void GetGroupsOntxt()
      {
          DataSet dsGetGroups = new DataSet();
          string ShowApartments = string.Empty;
          try
          {
              dsGetGroups = objCustomerMessageBusinessRule.GetApartmentNumber();
              if (dsGetGroups.Tables[0].Rows.Count > 0)
               {
                 for (int Apartment = 0; Apartment < dsGetGroups.Tables[0].Rows.Count; Apartment++)
                   {
 
                       ShowApartments = ShowApartments + dsGetGroups.Tables[0].Rows[Apartment]["ApartmentNumber"].ToString() + ",";
                   }
                 txtShowApartment.Text = ShowApartments.ToString();
              }
              else
              {
                  txtShowApartment.Text = string.Empty;
              }
          }
          catch (Exception ex)
          {
              EnterpriseLogger.HandleGeneralException(ex);
          }
      }


Thanks
 
Share this answer
 
C#
public void GetGroupsOntxt()
{
    string ShowApartments = string.Empty;
    try
    {
		DataSet dsGetGroups = objCustomerMessageBusinessRule.GetApartmentNumber();
		if (dsGetGroups.Tables[0].Rows.Count > 0)
		{
			foreach(DataRow dw in dsGetGroups.Rows)
				ShowApartments += dw["ApartmentNumber"].ToString() + ",";
			
			txtShowApartment.Text = ShowApartments;
        }
		else
        {
			txtShowApartment.Text = string.Empty;
		}
    }
    catch (Exception ex)
    {
		EnterpriseLogger.HandleGeneralException(ex);
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900