Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (dtProcedureDocs != null)
                        {
                            DataTable dt = GetProcedureDocssDatatable();
                            string DocTitleID = lstofWF.Where(o => o.FName == "Document Title").Select(s => s.FID).FirstOrDefault().ToString();
                            string DocCatID = lstofWF.Where(o => o.FName == "Document Category").Select(s => s.FID).FirstOrDefault().ToString();

                            foreach (DataRow sRow in dtProcedureDocs.Rows)
                            {
                                DataRow dr = dt.NewRow();
                                dr["Name"] = sRow["Name"];
                                dr["Document Title"] = sRow[DocTitleID];
                                dr["Document Type"] = sRow[DocCatID];
                                dr["Owner"] = sRow["OwnerGuid"].ToString();
                                dr["Created By"] = sRow["CreatedByGuid"].ToString();
                                dr["Created Date"] = String.Format("{0:M/d/yyyy}", sRow["CreatedDate"].ToString());
                                dr["Modified By"] = sRow["ModifiedByGuid"].ToString();
                                dr["Current Version"] = sRow["OwnerGuid"].ToString();

                                objTemplatesHelper.InsertRowInDocumentTable(table, dr);
                            }

                        }

 private DataTable GetProcedureDocssDatatable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Document Title", typeof(string));
            dt.Columns.Add("Document Type", typeof(string));
            dt.Columns.Add("Owner", typeof(string));
            dt.Columns.Add("Created By", typeof(string));
            dt.Columns.Add("Created Date", typeof(string));
            dt.Columns.Add("Modified By", typeof(string));
            dt.Columns.Add("Current Version", typeof(string));
            return dt;
        }


Q1 The main things i added here, dtProcedureDocs was fetched from DB & I am exporting the values in MSWORD,the output is not giving me like that ["dd/mm/yyyy"]

---------------------------------------------------------------------------------------------

Q2 If I change the datatype of created date to date time like below,,,then how can i format in the above code?
C#
private DataTable GetProcedureDocssDatatable()
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("Name", typeof(string));
           dt.Columns.Add("Document Title", typeof(string));
           dt.Columns.Add("Document Type", typeof(string));
           dt.Columns.Add("Owner", typeof(string));
           dt.Columns.Add("Created By", typeof(string));
           dt.Columns.Add("Created Date", typeof(datetime));
           dt.Columns.Add("Modified By", typeof(string));
           dt.Columns.Add("Current Version", typeof(string));
           return dt;
       }
Posted
Updated 21-Feb-13 8:52am
v3

Ali_100, start here: Data Types (C#)[^]. More here: Date Data Type[^]

Remember: Date is a date, string is a string!

If you want to store dates, you need to use date not string data type. Of course, you can always parse date from string, as is described here: http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx[^]...
 
Share this answer
 
I did it by the link
Click
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900