Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi


good evening

i am using the datagridview in c#.net in windows application
and more over iam getting the data from the excel sheet into the datadridview
but in total one column , there is the time like "4:00 PM"in excelsheet
but in the datagridview when iam loading with the sample data getting the same cloumn as "12/30/1899 4:00 PM"

"4:00 PM"
"12/30/1899 4:00 PM"

But i need this one only "4:00 PM"


so it was also showing the default date , i had tried a lot but no use i show my sample code


OleDbConnection cnCSV = new OleDbConnection(strConnectionString);
               cnCSV.Open();
               OleDbCommand cmdSelect1 = new OleDbCommand(@sgh, cnCSV);
               OleDbDataAdapter daCSV = new OleDbDataAdapter();
               daCSV.SelectCommand = cmdSelect1;
               DataSet ds = new DataSet();
               DataTable dtCSV1 = new DataTable();
               daCSV.Fill(dtCSV1);
               daCSV.Fill(ds, comboBox1.SelectedItem.ToString());
               daCSV = null;
               cnCSV.Close();
               return dtCSV1;




everything is working fine except that date part it as showing the extra part so please give me an idea , what to be changed to get the time as "4:00 PM" in datagridview in windwos application

please give me the suggestion fro me
Posted
Updated 7-Apr-11 5:14am
v2

1 solution

You need to set the this.daCSV.Columns["YourDateColumn"].DefaultCellStyle.Format into the format which best suits you needs. For details check this: http://msdn.microsoft.com/en-us/library/f9x2790s.aspx[^]
Regards
 
Share this answer
 
v2
Comments
[no name] 7-Apr-11 11:27am    
its an perfect one thanks a lot
really i mean it
Ciumac Sergiu 7-Apr-11 11:32am    
Hm, I was voted with 1 providing the right answer :)
Nuri Ismail 7-Apr-11 11:46am    
Hmmm, this answer is good, it is accepted by the OP with a positive feedback, so there are no reasons for this absurd 1-vote!

My 5 is heavier! ;)

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