Solved

converting datetime picker value in vb.net

Posted on 2010-08-26
7
566 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
  • 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 500 total points
ID: 33531685
It is:

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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AutoHotkey ActiveX Component Error 8 73
Round up to 100% in .NET 10 89
VB.NET bulk update  of a table from another table 4 36
Help with Query not working in client's PC 1 35
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now