Link to home
Start Free TrialLog in
Avatar of neoice
neoice

asked on

Convert date from mm/dd/yyyy to dd/mm/yyyy in Visual Basic.net

Hi,

I receive the following error at run time:

"error converting datatype varchar to datetime"
I imagine it's because it is trying to insert 10/16/2008 into my SQL DB wich is set to UK language.



Dim MyConn As SqlConnection
        Dim MyCmd As SqlCommand
        Dim MyCmd1 As SqlCommand

        Dim currentdate As Date

        currentdate = Date.Now

   



        Dim connectionstring As String = ConfigurationManager.ConnectionStrings("conn").ConnectionString

        MyConn = New SqlConnection(connectionstring)
        MyConn.Open()


        LblMessage.Text = currentdate
        MyCmd = New SqlCommand("execute tblstock_duplicateserial @serialnumber ='" & RTBCode.Text & "', @qty ='" & RTBQty.Text & "', @category='" & RCBCategory.Text & "', @items='" & RCBItem.Text & "', @location='" & RCBLocation.Text & "', @orderno='" & RCBPO.Text & "', @description='" & RTBDescription.Text & "',@lastactivitydate='" & currentdate & "'", MyConn)

        MyCmd.ExecuteScalar()
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Use parameters for stored procedure, your method is open to sql injection.

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx
Avatar of neoice
neoice

ASKER

Hi,

After hours of research on this I have found the answer!!!!!!!!!!!!!!

The SA account I used to send the data had the language set to english. Setting this to British resolved my problem!!!!!!!!!!

As I have solved my own problem, I am willing to give the points to anybody that can convert the above SQL to use parameters, proving I am allowed to do this?

Cheers
ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neoice

ASKER

Good memory!