Solved

converting datetime picker value in vb.net

Posted on 2010-08-26
7
565 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

17 Experts available now in Live!

Get 1:1 Help Now