Solved

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

Posted on 2008-10-16
4
296 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

18 Experts available now in Live!

Get 1:1 Help Now