我想在数据表中添加新列 [英] I want to Add a new column in datatable

查看:88
本文介绍了我想在数据表中添加新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据表是这样的

Dayid开始时间结束时间
1 10:00 12:00
2 11:00 1:00
3 9:00 5:00

我想更改Dayid和列.我想给天而不是dayid ..像1-sunday,2-monday ....像这样..我该怎么做..plz帮助我.....

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.....

推荐答案

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";


}


U可以先删除ur列,然后添加它,然后像周一,周二,周二那样手动插入ur day.也有很多方法-> u必须检查w3schools

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

ALTER TABLE ur_table_name
DROP COLUMN Dayid



然后再次添加->



then add it again-->

ALTER TABLE ur_tablename
ADD Dayid varchar(10)


之后,您可以将星期一,星期二放在........


after that u can put monday,tuesday.....


只需创建几天的枚举数并将初始变量的索引设为1,然后将值从数据库强制转换为枚举字段以便显示相应的日期名称.


枚举天数
{
星期一= 1,
星期二,
星期三,
...
周日
};


Days day = new Day(5);
一天包含星期五"
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''


这篇关于我想在数据表中添加新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆