问题发送到sqlserver的日期 [英] problem into date sending to sqlserver
问题描述
你好,
我在发送到sqlserver 2008的日期时遇到了问题,在我的PC上将其发送到远程sql日期格式为"dd/MM/yyyy",并且一切正常.
但是当我在远程服务器iis7上发布网站时,sql server收到的日期为MM/dd/yyyy
并显示字符串未被识别为有效日期时间"问题,远程服务器格式日期为dd/MM/yyyy.
当我将iis7上已发布页面的格式更改为MM/dd/yyyy时运行
任何帮助
hello,
i have problem into date that sending to sqlserver 2008 , on my pc i send to remote sql date format ''dd/MM/yyyy'' and every thing is ok.
but when i published web site on remote server iis7 ,sql server receive date as MM/dd/yyyy
and the problem "the string was not recognized as valid datetime " show , remote server format date is dd/MM/yyyy .
when i change format for published page on iis7 to MM/dd/yyyy its run
any help
推荐答案
希望您正在使用.NET.请始终在您的问题中向我们提供完整的详细信息.
看看这些答案,就这些了.<br/>
答案1 [答案2 [答案3 [
Hope you are using .NET. Always give us complete details in your question.
Look at these answers, that''s all.
Answer 1[^]
Answer 2[^]
Answer 3[^]
大多数情况下,TSQL的日期参数都应包含在#"标记中
即:#21/6/2011#而不是"21/6/2011",您也可以尝试执行此操作.
Most of the cases date parameters to TSQL should wrap with in ''#'' tags
ie: #21/6/2011# instead of ''21/6/2011'', you can also try this.
请确保您对数据使用SQL参数访问
http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx [ ^ ]
我从那篇文章中摘录了一些代码
Make sure you''re using SQL parameters for your data access
http://weblogs.sqlteam.com/jeffs/archive/2006/07/21/10728.aspx[^]
I''ve lifted a bit of code from that article
Dim cm As New SqlCommand("", YourConnection)
cm.CommandText = "DELETE FROM YourTable WHERE ID=@ID and Name=@Name and TranDate=@TranDate"
cm.Parameters.Add("@ID", SqlDbType.Int).Value = ID
cm.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name
cm.Parameters.Add("@TranDate", SqlDbType.DateTime).Value = TranDate
cm.ExecuteNonQuery()
注意,我用粗体显示的行-通过使用参数,可以完成所有日期转换,而您不会遇到这个问题.
Notice the line I''ve bolded - by using parameters all date conversions are taken care of and you don''t have this problem.
这篇关于问题发送到sqlserver的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!