Click here to Skip to main content
11,644,286 members (64,299 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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:

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 15-Oct-12 20:44pm
Comments
chetan virkar at 16-Oct-12 2:56am
   
where is the problem
what error it show.
AshishChaudha at 16-Oct-12 3:06am
   
whats the problem??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

A minor problem my friend

Instead of

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

use,


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
  Permalink  
Comments
aravindnass at 18-Oct-12 7:24am
   
thanks ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
	}
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 610
1 jyo.net 484
2 Afzaal Ahmad Zeeshan 453
3 Sergey Alexandrovich Kryukov 369
4 CPallini 352
0 OriginalGriff 925
1 DamithSL 636
2 Afzaal Ahmad Zeeshan 622
3 Sergey Alexandrovich Kryukov 548
4 CPallini 521


Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100