Click here to Skip to main content
16,012,759 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My datatable is like this

Dayid Starttime EndTime
1 10:00 12:00
2 11:00 1:00
3 9:00 5:00

I want to change the column Dayid and .I want to give days instead of dayid..like 1-sunday,2-monday....like this..how can i do this..plz help me.....
Posted

C#
yourdatatable.Columns["Dayid"].ColumnName = "YourDesiredName";
Then get days and add as its value for your row column with foreach loop:

foreach(DataRow myRow in table.Rows)
{

    myRow[1]["YourDesiredName"] = "day";


}
 
Share this answer
 
U can drop ur column and then add it, then insert ur day like-monday,tuesday..manually. Also there are many approaches for it-->u have to check w3schools

SQL
ALTER TABLE ur_table_name
DROP COLUMN Dayid


then add it again-->
SQL
ALTER TABLE ur_tablename
ADD Dayid varchar(10)

after that u can put monday,tuesday.....
 
Share this answer
 
Comments
Member 9492907 5-Nov-12 6:55am    
I am not talking about the tables in sql..It is a datasource for a repeater...I want to check the dayid using a loop then only replace the value
StackQ 5-Nov-12 7:00am    
means u want to check this column for each value of column dayid,and if there is value like (1,2,3....) then replace it (1 replace with monday,then 2 with tuesday and so on) and if there is already (monday,tuesday,3,4) then only want to replace 3 and 4 with their respective values. m i right?
Just create an enumerator variable for days and give the index as 1 for the initial variable and cast the value from database to enum field so that it'll display the respective day name.


enum Days
{
Monday=1,
Tuesday,
Wednesday,
...
Sunday
};


Days day=new Day(5);
day contains 'Friday'
 
Share this answer
 
Change column name using this command sp_RENAME 'Table_Name.dayid', 'days ' , 'COLUMN'
 
Share this answer
 
simply type in sqlserver


use databasename

alter table tablename add columnname datatype constraint

where datatype==may be int ,varchar whatever

and constraint like null or not null etc

and then check your table
 
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