开发者

DataTable.Select expression fails using DateTime equals filter

I have some data retrieved from a database which I hold in a data table. What I want to do is extract only records that have a match to the date passed as a parameter only if it's greater than DateTime.MinValue(). This should be easy.

Below is the code snippet of how I build the query string. I know that if I don't have the date filter I get 'x' records but I always get 0 with the date filter.

    string query = string.Format("Field_Name IN( 'GENDER','DOB','MARITAL_STATUS','SS') AND DIFF_TYPE = 'PER' AND Person_ID = '{0}'", Person_ID);

    if (ChangeDetected > DateTime.MinValue)
    {
        query += string.Format(" AND ChangeToDT = #{0}#", ChangeDetected);
    }

    ChangeDataSet.DifferencesRow[] perChanges = this.m_ChangeDS.Differences.Select(query, "ChangeFromDT ASC, Field_Name DESC") as ChangeDataSet.DifferencesRow[];

I have tri开发者_StackOverflow中文版ed all sorts of variations on outputting format for the DateTime in the filter but they all have the same result.

I don't know enough LINQ to do the conditional filter that way either. {:o(


Try specifying the format directly:

query += string.Format(" AND ChangeToDT = #{0}#", ChangeDetected.ToString("MM/dd/yyyy"));

BTW: This has nothing to do with LINQ.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜