Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

converting datetime picker value in vb.net

Posted on 2010-08-26
7
Medium Priority
?
573 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:Meir Rivkin
ID: 33531646
cmd.Parameters("@date_val").Value = Format(Me.DateTimePicker2.Text.ToString,"YYYY/MM/DD")
0
 
LVL 42

Expert Comment

by:Meir Rivkin
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
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.

 
LVL 42

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
ID: 33531849
is this doesn't work???

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

Featured Post

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.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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