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
Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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