?
Solved

converting datetime picker value in vb.net

Posted on 2010-08-26
7
Medium Priority
?
572 Views
Last Modified: 2012-05-10
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
Comment
Question by:alsam
[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
  • 4
  • 2
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531646
cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"YYYY/MM/DD")
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531664
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
 
LVL 17

Accepted Solution

by:
Zhaolai earned 2000 total points
ID: 33531685
It is:

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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 42

Expert Comment

by:sedgwick
ID: 33531687
wrong again, that will do it:cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"yyyy/mm/dd"))
0
 
LVL 1

Author Comment

by:alsam
ID: 33531818
It returns

Syntax error converting datetime from character string.

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33531847
Have you tried my solution?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 33531849
is this doesn't work???

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

Featured Post

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.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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