如何将年份和月份绑定到数据集? [英] How to Bind Year and Months to Dataset ?

查看:63
本文介绍了如何将年份和月份绑定到数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要通过C#代码或Sql Server Fucntion或Procedure将数据绑定到datset,从当前月份和年份开始。

如果有人知道你告诉我答案的话。



Hi,
I need to bind data to datset as Years and Months in Below foramt from current month and year through C# code or Sql Server Fucntion or Procedure.
if any one know colud you tell me the answer.

Year    Month
2013    May
2013    June
2013    July
2013    August
2013    September
2013    October
2013    November
2013    December
2014    January
2014    February
2014    March
2014    April





问候

Nanda Kishore.CH



Regards
Nanda Kishore.CH

推荐答案

下面的方法将返回DataSet,其中包含您想要的数据。



Below method will return DataSet with data what you exactly want.

private DataSet GetListOfMonths(int range)
{
    DataSet ds = new DataSet();
    ds.Tables.Add("Months");
    ds.Tables["Months"].Columns.Add("Year");
    ds.Tables["Months"].Columns.Add("Month");
    DateTime dtCurrent = DateTime.Now;
    for (int i = 0; i < range; i++)
    {
        DataRow dr = ds.Tables["Months"].NewRow();
        dr["Year"] = dtCurrent.Year;
        dr["Month"] =System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dtCurrent.Month);
        ds.Tables["Months"].Rows.Add(dr);
        dtCurrent = dtCurrent.AddMonths(1);
    }

    return ds;
}


这篇关于如何将年份和月份绑定到数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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