Joergen,
Net is been able to overcome the problems as they have forever been with
giving hardcoded dates to database servers.
I am very glad that it is done, this does it not make needed anymore to use
systems as they where in the time of the punch card, for which ISO 8601 is
really faremost the best method.
For a direct answer on your latest question in the most simple way.
http://www.vb-tips.com/default.aspx?ID=886bba68-8a2f-4b99-8f66-7139b8970071
(This even works if the setting is Danish as day fullmonthname (written in
Danish) year)
I hope this gives the idea
Cor
So I type this up:
---snip---
Private Sub CommandTest2()
Dim conn As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection
conn.ConnectionString = "Data Source=JB;Initial
Catalog=Northwind;User Id=sa;Password=;"
conn.Open()
Dim dsNorthwind1 As New DataSet()
Dim da As New SqlClient.SqlDataAdapter()
Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Orders
WHERE OrderDate >= @STARTDATE", conn)
cmd.Parameters.Add("@STARTDATE", SqlDbType.DateTime)
cmd.Parameters("@STARTDATE").Value = New Date(1998, 1, 1)
da.SelectCommand = cmd
da.Fill(dsNorthwind1)
dsNorthwind1.WriteXml("d:\out.xml")
conn.Close()
End Sub
---snip---
and what the SQL Server Profiler sees as a result of running this is
---snip---
exec sp_executesql N'SELECT * FROM Orders WHERE OrderDate >=
@STARTDATE', N'@STARTDATE datetime', @STARTDATE = 'Jan 1 1998
12:00:00:000AM'
---snip---
That is horrible. I haven't bothered to check if that is actually the
text transferred across the wire (can anyone confirm this?), but I
am fairly positive that this is the case.
I understand that this might make the code more readabable on the
..Net side, but (leaving SQL 2005 and its bulk copy functions outside
this discussion) there are situations where this approach would be
highly inefficient, e.g. in cases where a lot of data needs to be
transformed and sent to the server.
If those command parameter values are sent to the server in
a binary format without going through a .NetNative->Text->SQLNative
transformation, I would tend to agree with you. If not, .Net is just
hiding the details from you and there will be situations where you
will want to skip the overhead and prepare the SQL yourself.
But that is probably another discussion for another newsgroup.
"Punch cards" are alive and well.
Regards,
Joergen Bech