?
Solved

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

Posted on 2008-10-16
4
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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