DATE HELLLPPPP

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi
I have a vb.net app asp.net 1.1 that uses "NOW" to get the date and the
uses a sql statement to write it to an MS SQL server remotely hosted!

Well the date has flipped to 13/01/2006 the data base wants it in US format
what's the best way of changing it?!

I tried format(now, "MM/DD/YYYY HH:MM:SS") but this just gives me an error
Cast from string "01/DD/YYYY 15:01" to type 'Date' is not valid.


HELLPP
 
Adrian,

Be aware that the IDE from VBNet shows dates between ## in USA format.
(Don't be confused if you use C# as well, that IDE shows the datetime in
your local setting).

The actual DateTimes are in ticks (Starting in 1753 for SQL server and at
1-1-1 for Net).

Therefore try to avoid any fixed changes from a datetime, normally Net does
that for you.

Cor
 
Adrian said:
Hi
I have a vb.net app asp.net 1.1 that uses "NOW" to get the date
and the uses a sql statement to write it to an MS SQL server
remotely hosted!

Well the date has flipped to 13/01/2006 the data base wants it in US
format what's the best way of changing it?!

I tried format(now, "MM/DD/YYYY HH:MM:SS") but this just gives me
an error Cast from string "01/DD/YYYY 15:01" to type 'Date' is not
valid.

Use parameters:

sqlcommand.parameters.add("@param", sqldatatype.datetime").value = now


Armin
 
Hi,
Thanks, I got around it for now by using substring to re construct the
date! as this SQL is new to me:(

So if I use parameters how do I do it?

is each part of the query constructed using it?

how would i use it to say do this:
Cmd = New SqlCommand(strSql, Conn)
strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY) VALUES('" &
dateTStamp & "', '" & strXXX & " ','" & strIP & "' ,'" & strYYY & "')"
Conn.Open()
Cmd.ExecuteNonQuery()

thanks
 
Adrian said:
Hi,
Thanks, I got around it for now by using substring to re construct
the date! as this SQL is new to me:(

So if I use parameters how do I do it?

is each part of the query constructed using it?

how would i use it to say do this:
Cmd = New SqlCommand(strSql, Conn)
strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY)
VALUES('" & dateTStamp & "', '" & strXXX & " ','" & strIP & "' ,'" &
strYYY & "')" Conn.Open()
Cmd.ExecuteNonQuery()


You'll find many samples if you press <F1>. ;-)


strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY) VALUES(@Stamp,
@xxx, @ipadress, @yyy)
Cmd = New SqlCommand(strSql, Conn)
with cmd.parameters
.add("@stamp", sqldbtype.datetime).value = stamp
.add("@xxx", sqldbtype.varchar).value = xxx
.add("@ipaddress", sqldbtype.varchar).value = ipaddress
.add("@yyy", sqldbtype.varchar).value = yyy
end with

Conn.Open()
Cmd.ExecuteNonQuery()


Variable stamp should be declare as DateTime, the others as string. I
assumed that xxx, ipaddress and yyy are varchar in the database.


If you will have further ADO.Net (language unrelated) questions,
microsoft.public.dotnet.framework.adonet is the best place to ask.


Armin
 
Great thanks for your help

Armin Zingler said:
You'll find many samples if you press <F1>. ;-)


strSql = "INSERT INTO DownloadLog(Stamp, XXX, IPAddress, YYY)
VALUES(@Stamp, @xxx, @ipadress, @yyy)
Cmd = New SqlCommand(strSql, Conn)
with cmd.parameters
.add("@stamp", sqldbtype.datetime).value = stamp
.add("@xxx", sqldbtype.varchar).value = xxx
.add("@ipaddress", sqldbtype.varchar).value = ipaddress
.add("@yyy", sqldbtype.varchar).value = yyy
end with

Conn.Open()
Cmd.ExecuteNonQuery()


Variable stamp should be declare as DateTime, the others as string. I
assumed that xxx, ipaddress and yyy are varchar in the database.


If you will have further ADO.Net (language unrelated) questions,
microsoft.public.dotnet.framework.adonet is the best place to ask.


Armin
 
Back
Top