簡體   English   中英

如何從asp.net中的“日期”列數據表中比較月份和年份?

[英]How to compare month and year from Date column data table in asp.net?

在我的數據表中,有Date列和我輸入的txtmonth Textbox and txtyear textbox 如果它們等於郵件valid Date需要將月份和年份中的Date列的數據表與txtmonth and txtyear textboxes進行比較。

我的密碼

上面的代碼我確實喜歡比較單個記錄,但是我需要一次檢查所有記錄,我該怎么做?

@本805

bool Ismatch=false;

DataTable dt = new DataTable;
            int FilteCarriercount = (from q in dt.AsEnumerable()
                                   where q.Field<string>("Date").ToString().Split('/')[0] == txtmonth.Text &&
                                   q.Field<string>("Date").ToString().Split('/')[2] == txtyear.Tex
                                      select new 
                                      {
                                          date = q["Date"],

                                      }).ToList().Count;

If(FilteCarriercount >0)
{
  lblmessage("You Uploaded Valid document");
}
else
{
  lblmessage("You Uploaded is not Valid document");
}

請檢查上面的代碼。 謝謝。

您可以使用布爾值,如下所示:

DataTable dt = new DataTable;
bool success = true;
for (int i = 0; i < dt.Rows.Count; i++)
{
    string date = dt.Rows[i]["Date"].ToString();
    string[] date1 = date.Split('/');
    string month = date1[0];
    string year = date1[2];
    if (month != txtmonth.Text || year != txtyear.Text)
    {
        success = false;
        break;
    }
}
if (success)
{
    lblmessage("You Uploaded Valid document");
}
else
{
    lblmessage("You Uploaded is not Valid document");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM