cmd.Parameters.Add("@Date", dtp_Date.Value);
This code is inserted date in "M/dd/yyyy" format but I want to insert date in dd-MM-yyyy format in ms access database.
cmd.Parameters.Add("@Date", dtp_Date.Value);
This code is inserted date in "M/dd/yyyy" format but I want to insert date in dd-MM-yyyy format in ms access database.
You can store DateTime in any format in Database.
You require to convert when you want to show it on screem(e.g. View)
For that case use DateTime.TryParseExact:
DateTime dtReturn;
DateTime.TryParseExact(dtp_Date.Value, 'dd-MM-yyyy', CultureInfo.InvarientCulture, DateTimeStyles.None, out dtReturn);
I'm assuming your database field type is 'datetime' and dtp_date is ''String. If so, use the below line of code,
DateTime date = DateTime.ParseExact(dtp_Date, "dd-MM-yyyy", null);
By assuming that you are inserting into a mysql database, it supports only yyyy-mm-dd format for date. you can format the date while retrieving it from the DB. Link for mysql date functions
Datetime in ms access is not stored with it's display format. In fact, it's stored as a double:
Access stores the Date/Time data type as a double-precision, floating-point number up to 15 decimal places. The integer part of the double-precision number represents the date. The decimal portion represents the time.
You should deal with display format when selecting from the table.