Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I have a Datatable with values like
SQL
ID              PercentofSales
1                 0
2                 25
3                 50
4                 75


This is wat i do :
VB
For Each dr As DataRow In m_dtPercentofSales.Rows
           Me.cmbPercentofSales.Items.Add(dr("PercentofSales"))
       Next


But how do i append % symbol to the PercentofSales column. I can add the % to the SQL Table by making the column Datatype as Varchar but i dont want to do that. Please help.

Thanks.
Posted
Updated 8-Jul-13 3:22am
v3
Comments
Zoltán Zörgő 8-Jul-13 9:11am    
You should add this formatting on presentation level and not in the DAL level.

Hi,

Could you make this in your Query like this....
SQL
SELECT ID, CAST(PercentofSales AS VARCHAR(10))+'%' AS PercentofSales FROM yourtable

Regards,
GVPrabu
 
Share this answer
 
v2
Comments
vidkaat 8-Jul-13 9:27am    
Thank you so much.
gvprabu 8-Jul-13 9:33am    
welcome
Maciej Los 8-Jul-13 9:48am    
+5
gvprabu 8-Jul-13 9:50am    
thank u yar....
Zoltán Zörgő 8-Jul-13 14:05pm    
Your answer is technically correct. But you have confirmed a bad practice.
Try this
C#
foreach (DataRow row in MyDataTable.Rows)
{
 row["columnNameHere" Or index] = value;
}


Hope this helps
 
Share this answer
 
Comments
vidkaat 8-Jul-13 9:20am    
But i need to concatenate the symbol % to the column. How do i do this?
Jameel VM 8-Jul-13 9:25am    
you should concatenate the % with that particular column like row["columnNameHere" Or index] = "%"+ row["columnNameHere"]

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