pavan496:Similarly, i changed the format of the date field in access 2007 table to dd/MM/yyyy wherever needed.
This is nonsense. What you're doing there is specifying how a date is represented when you're using Access as application. But also in the access application, ýou did not, and you can not specify how a date is stored internally. In fact, all dates in Access are stored as numbers! But In an ASP.NET environment, you're not dealing with an access database, but with a Jet Database Engine. When you are entering dates in aa/bb/cccc format, Jet willl thread that as according to the culture.
When you set a culture, then all dates (and numbers) are shown by default according to that culture. If you didn't set a culture, ASP.NET uses the culture of the users browser. When a user is entereing a date in a textbox, the same is happening. So when you have a textbox where a user entered a date. all you need to do is convert it to a datetime:
dim aDate = Convert.ToDateTime(TextBox1.Text)
The Date in the TextBox will be handled as specified in the culture, either the culture of the users browser, or, if you did set a culture in web.config, by that culture
A simple test will show what I just explained
Drag a textbox (TextBox1), a Label (Label1) and a Button (Button1) on a Form. In the code behind enter:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim aDate As DateTime = Convert.ToDateTime(TextBox1.Text)
TextBox1.Text = aDate.ToShortDateString
Label11.Text = aDate.Day.ToString
End Sub
When you set the Culture in web.config to en-GB, and enter 2/1/2009 in the textbox and click the button, the label will show that the day is 2
When you enter 2/13/2009, that it will throw an error, because it isn't a valid date, because 13 is threated as the month
When you change the CUltue in web.config to en-US and enter 2/1/2009, the label will show that the day is 1
When you enter 2/13/2009, the label will show that the day is 13
And when you enter 13/1/2009, it will throw an error
One more thing. When entering data in a database, always use parmeterized queries
http://www.mikesdotnetting.com/Article.aspx?ArticleID=26
when entering a date, convert the date into a Ole Automation date:
cmd.Parameters.AddWithValue("DateField", Convert.ToDateTime("DateString").ToOADate)