Home All Groups Group Topic Archive Search About
Author
13 Jan 2006 3:36 PM
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

Author
13 Jan 2006 4:01 PM
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
Author
13 Jan 2006 4:14 PM
Armin Zingler
"Adrian" <Adrian@nospamhotmail.com.uk> schrieb
> 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
Author
13 Jan 2006 6:11 PM
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


Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:un8mXqGGGHA.208@tk2msftngp13.phx.gbl...
> "Adrian" <Adrian@nospamhotmail.com.uk> schrieb
>> 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
>
>
>
Author
13 Jan 2006 6:44 PM
Armin Zingler
Show quote Hide quote
"Adrian" <Adrian@nospamhotmail.com.uk> schrieb
> 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
Author
13 Jan 2006 6:52 PM
Adrian
Great thanks for your help

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:eNrauGHGGHA.2212@TK2MSFTNGP15.phx.gbl...
> "Adrian" <Adrian@nospamhotmail.com.uk> schrieb
>> 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