Wrox Programmer Forums
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 8th, 2004, 10:02 AM
Authorized User
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date problem

Hi everybody
On page i have text box txtDate. User writes date in dd.mm.yyyy format.

When the button btnSearch is clicked i have to query sqlserver 2000 database. Here is a code:

Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    If Trim(txtDate.Text) <> "" Then
        Dim dCreatedFrom As Date
            dCreatedFrom = CDate(Trim(txtDate.Text))
        Catch ex As Exception
        End Try

        strSQL =" Select * from Orders Where OrderDate >= '" & Format(dCreatedFrom, "YYYY.MM.DD") & "'"
    End If
End Sub

When i return dataset with this strSQL i always get the error:
 Syntax error converting datetime from character string
How can i solve this
Old January 8th, 2004, 10:19 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts

This isn't the answer but I think this is more correct with your If Statement.

If Not Trim(txtDate.Text) Is Nothing Then

Or you can use a requiredfieldvalidator to make sure it contains a value.

Old January 8th, 2004, 12:29 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts

Have your tried using the FormatDateTime Function?

Like this:

FormatDateTime(dCreatedFrom, DateFormat.ShortDate)

Old January 14th, 2004, 05:22 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts

SQLServer 2000 looks for a date to be passed in as a string. You define the parameter as a datetime in the stored procedure but in your VB code you need to pass it as a string.

strSQL =" Select * from Orders Where OrderDate >= " + "' mm/dd/yyyy + '"

you can specify the date in any acceptable format yyyy/dd/mm ... etc .. . but it must be a string.

Similar Threads
Thread Thread Starter Forum Replies Last Post
DATE PROBLEM ricespn Classic ASP Basics 3 October 20th, 2006 07:15 AM
Date Problem. rupen Classic ASP Basics 3 June 3rd, 2005 09:58 AM
Date Problem tdaustin Classic ASP Basics 10 August 13th, 2004 01:43 PM
date problem hosefo81 PHP How-To 2 May 26th, 2004 11:12 AM
Date problem Larson VB How-To 2 December 30th, 2003 06:10 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.