1

I have database with column of date type My computer run on date format MM/dd/yyyy "en-us" I have grid view which I used to insert data from GV to data base using the insert SQL command it work fine with out any exception.

When I try to change my computer date format to dd/MM/yyyy it give my exception when I run my application ("Does not allow to insert data from GV to data base column of date data type")

How can I solve this exception any help please?

user3183270
  • 135
  • 1
  • 8

2 Answers2

1

Based on your description, it sounds as though you are using inline SQL to write the records to the database. If this is the case, then the correct approach is to format the DateTime in a standard way.

For SQL Server, the standard format is

theDate.ToString("yyyy-MM-dd HH:mm:ss.000")

However, it is strongly recommended to use parameterized SQL instead of inline SQL if possible (there are situations where it is not practical or possible). In this case, the parameters will handle the formatting of the date correctly so you don't have to worry about it.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
0

Try to use DateTime.ParseExact link to stackoverflow

In your case parsing from string to DB would be look like this

string s = "01/10/2014"; // format dd/MM/yyyy

DateTime dt = 
DateTime.ParseExact(s, "dd/MM/yyyy", CultureInfo.InvariantCulture);
Community
  • 1
  • 1
Tomcat
  • 36
  • 1
  • 4