Visual Studio Development Bookmark and Share   
 index > Visual C# Express Edition > Cannot format a datetime column in a dataset
 

Cannot format a datetime column in a dataset

Hi
I have two excel files having some 10 columns each with some date fields. I have a task to merge these two excel files and compare the dates. I am able to load the excel files in the datasets but the format of the date columns are defaulted to mm/dd/yyyy hh:mm:ss. I am not sure how can I store the excel data with date as mm/dd/yyyy.
Following is the code that I use to populate the dataset with an excel file. Is there any way to format the date column when I store it into a dataset or modify an existing dataset with formatting of date columns. I can't format it during display as I bump the merged dataset back into excel file so I don't have a way to format before export.
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.xls;Extended Properties=Excel 8.0;";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT Last_Name,First_Name,Completion_Date,Completion_Date2,Completion_Date3,Completion_Date4 FROM " + table + " WHERE Last_Name IS NOT NULL ORDER BY Last_Name, First_Name";
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;
adapter.SelectCommand = selectCommand;
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;


Your help is much appreciated!
Regards
kuul13  Tuesday, October 13, 2009 1:54 PM
thanks guys!

I got the answer now.. I used format function within the query as suggested by someone:
SELECT Last_Name,First_Name,Completion_Date,format(Completion_Date2,'mm/dd/yyyy'),format(Completion_Date3,'mm/dd/yyyy'),format(Completion_Date4,'mm/dd/yyyy') FROM " + table + " WHERE Last_Name IS NOT NULL ORDER BY Last_Name, First_Name.
kuul13  Tuesday, October 13, 2009 7:47 PM
thanks guys!

I got the answer now.. I used format function within the query as suggested by someone:
SELECT Last_Name,First_Name,Completion_Date,format(Completion_Date2,'mm/dd/yyyy'),format(Completion_Date3,'mm/dd/yyyy'),format(Completion_Date4,'mm/dd/yyyy') FROM " + table + " WHERE Last_Name IS NOT NULL ORDER BY Last_Name, First_Name.
kuul13  Tuesday, October 13, 2009 7:47 PM

You can use google to search for other answers

Custom Search

More Threads

• RichTextBox - cursor control
• Makeing C# library & calling from other appliction
• MouseEnter erratic
• How to check whether given value is alphabet or not in a combo box(Drop Down style)
• Creating a search engine
• code text editor
• how do i execute a command when i press a button
• what is the problem?
• How to develop good knowledge in C#?
• Binding Navigator