DATE HELLLPPPP

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
 
C

Cor Ligthert [MVP]

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
 
A

Armin Zingler

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
 
A

Adrian

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
 
A

Armin Zingler

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
 
A

Adrian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top