• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

converting datetime picker value in vb.net

Hi,
I'm trying to conver datetime picker value dd.mm.yyyy into yyyy.mm.dd and pass it as param value in my vb.net code to execute delete command.
Unfortunatelly it does not work this way. Can someone help me...
Thanks
Dim cmd As New System.Data.SqlClient.SqlCommand()
            cmd.Connection = cn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "DELETE FROM BAL_SHEET WHERE DATE_VAL = @date_val"
            cmd.Parameters.Add("@date_val", SqlDbType.NVarChar)
            cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"YYYY.MM.DD"))
            cmd.ExecuteNonQuery()

Open in new window

0
alsam
Asked:
alsam
  • 4
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"YYYY/MM/DD")
0
 
Meir RivkinFull stack Software EngineerCommented:
my mistake, better use the following:
Dim cmd As New System.Data.SqlClient.SqlCommand()
            cmd.Connection = cn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "DELETE FROM BAL_SHEET WHERE DATE_VAL = @date_val"
            cmd.Parameters.Add("@date_val", SqlDbType.NVarChar)
            cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"YYYY-MM-DD"))
            cmd.ExecuteNonQuery()

Open in new window

0
 
ZhaolaiCommented:
It is:

cmd.Parameters("@date_val").Value = Me.DateTimePicker2.Value.ToString("yyyy.MM.dd")

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Meir RivkinFull stack Software EngineerCommented:
wrong again, that will do it:cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"yyyy/mm/dd"))
0
 
alsamAuthor Commented:
It returns

Syntax error converting datetime from character string.

0
 
ZhaolaiCommented:
Have you tried my solution?
0
 
Meir RivkinFull stack Software EngineerCommented:
is this doesn't work???

cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString("yyyy/mm/dd"))
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now