开发者

need help with date in C# + access

in access 2007: i have field type date - in shortDate format

in my computer: i have region date dd/MM/yyyy

in my C# program: in the DateTimePiker i have format: short, CustomFormat: dd/MM/yyyy

the problem is: when i insert the value from DateTimePiker to access i got it in wrong format

for example:

i insert in DateTimePiker:开发者_如何学Python 03/08/2007

i get in access: 08/03/2007

i insert the data like this: "insert into MyTbl (MyDate) values (#" + dt_From.Value + "#)"

thanks in advance


Make sure you call DateTime.ToOADate() (eg, shortDate.ToOADate()), which converts the date to an OLE Automation date

http://msdn.microsoft.com/en-us/library/system.datetime.tooadate.aspx


You can transform your date format to access format using this

   DateTime dt = DateTime.Now;
   string str = dt.ToString("MM/dd/yyyy");
   string str1 = dt.ToString("dd/MM/yyyy");

Here in your code you can apply this for dt_From.Value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜