Solved

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

Posted on 2008-10-16
4
306 Views
Last Modified: 2013-11-26
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()
0
Comment
Question by:neoice
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22734071
Use parameters for stored procedure, your method is open to sql injection.

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx
0
 

Author Comment

by:neoice
ID: 22735126
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
0
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 22735292
Dont have an ide on me so this is from memory., i presume its a sproc

MyCmd  = new SqlCommand("tblstock_duplicateserial",MyConn)
MyCmd.CommandType = CommandType.StoredProcedure

dim param  as SqlParameter = new SqlParameter()
param.ParameterName = "@serialnumber"
param.Value = RTBCode.Text
MyCmd.Parameters.Add(param)
**DO THIS FOR EACH PARAMETER
MyCmd.ExecuteScalar()
0
 

Author Closing Comment

by:neoice
ID: 31506843
Good memory!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short film showing how OnPage and Connectwise integration works.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now