Retrieving a DateTime value from a DataRow (C#)

后端 未结 8 1422
别跟我提以往
别跟我提以往 2020-12-09 04:06

How can I get DateTime value in C# from row, the current code is giving me error any help is appreciated, the data is coming in from progress database:

8条回答
  •  Happy的楠姐
    2020-12-09 04:24

    foreach (DataRow r in ds.Tables[0].Rows)
    {
        string prodCode = r["PRD-CDE"].ToString();
        string statCode = r["STAT"].ToString();
        DateTime firstIssueDate = DateTime.Parse((r["FISS"]).ToString()); 
        DateTime endIssueDate = DateTime.Parse((r["EISS"]).ToString());
        if(endIssueDate > DateTime.Now)
        { /*do some thing...*/}
        else {/*user invalid...*/}
    }
    

    This should compile and may work for you. Though it is certainly not performing any error checking that you should do for production code. Also look into DateTime.TryParse and you may to look into adding a IFormatProvider to ensure the format is parsed as expected.

提交回复
热议问题