how compute a datatable on spaces of columns name for sum

Posted by Cpatil1000 under ASP.NET on 8/21/2013 | Points: 10 | Views : 6792 | Status : [Member] | Replies : 2
hi,
I have datatable , in the datatable my columns have space with name as like 'SAKHARE DAM' but problem is that datatable never accept spaces withing column name, so i can take compute for sum. I am dynamitically add columns in the datatable. mean i am doing as pivot table. The rows create as a column for gridview headers. Other wise if add a column with 'SAKHAR_DAM' as like underscore then how remove/ replace with space..

thanks..




Responses

Posted by: Bandi on: 8/21/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
while retrieving data from database itself use REPLACE() to replace with _
[code]
select replace(raw_source, ' ', '_')
from tablename[/code]


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/22/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Column name with space will cause several problems... refer the same in the follwoing link...
http://stackoverflow.com/questions/5029835/is-it-possible-to-have-a-datacolumn-with-a-space-in-the-name-and-how-can-i-do-it
So better to go ahead with replacing space with underscore (_)....
For pivoting also you have retrieve data from database... At that time only do the following modification
Assume that table name is Sample
SELECT * 

FROM (SELECT col1, col2, ...., REPLACE(RAW_SOURCE, ' ', '_') AS RAW_SOURCE, REPLACE(PURE_SOURCE, ' ', '_') AS PURE_SOURCE
FROM Sample
) T
PIVOT ( MAX(MBR) FOR RAW_SOURCE IN ('SAKHARE DAM')) pvt



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response