Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 June 9th, 2006, 10:18 AM
Registered User
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display data within data range?


I have a webform with a datagrid, 2 textboxes and a button. The datagrid is
filled by a sql database.
 I want is: to search the database for Range of data based on the Date I specify in the 2

Anytime I try to load the page I get this error:

My Code:

 Dim strConnection As String
            Dim strSQL As String
            Dim DBTable As DataTable

            Dim connection As New SqlConnection("server=Server1;uid=sa;pwd=;database =eProducts")

            Dim command As New SqlDataAdapter("SELECT * FROM Products Where SuppliedDate between (@Date1,@Date2)", connection)

            Dim param1 As New SqlParameter("@Date1", SqlDbType.DateTime)
                    param1.Value = Date1.Text
        Dim param2 As New SqlParameter("@Date2", SqlDbType.DateTime)
                    param1.Value = Date2.Text

                    Dim dataset As New DataSet
                    command.Fill(dataset, "Products")
            dgBooks.DataSource = Source

Getting this Error:
Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

Line 48:
Line 49: Dim dataset As New DataSet
Line 50: command.Fill(dataset, "Products")
Line 51: dgBooks.DataSource = Source
Line 52: dgBooks.DataBind()

and if i try to change the Date1.Text and Date2.text to "1/2/2002" and "6/6/2006" respectively
I get this Error also:

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ','.

Source Error:

Line 48:
Line 49: Dim dataset As New DataSet
Line 50: command.Fill(dataset, "Products")
Line 51: dgBooks.DataSource = Source
Line 52: dgBooks.DataBind()

Please can some help me out. All i want to do is to display the data in the range of data i specify in the textboxes.


Old June 9th, 2006, 10:34 AM
Friend of Wrox
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts

You're syntax for using BETWEEN is not correct.

Here's an example:

USE pubs
SELECT title_id, ytd_sales
FROM titles
WHERE ytd_sales BETWEEN 4095 AND 12000

This syntax is in the BOL.

Old June 9th, 2006, 03:06 PM
Authorized User
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via AIM to anujrathi Send a message via MSN to anujrathi Send a message via Yahoo to anujrathi

param1.Value = Convert.ToDateTime(Date1.Text)
param2.Value = Convert.ToDateTime(Date2.Text)

Similar Threads
Thread Thread Starter Forum Replies Last Post
varying data range stealthdevil Excel VBA 6 July 27th, 2007 02:30 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 07:17 AM
Return Data from Excel 97 Range into table interrupt Javascript How-To 3 March 4th, 2005 07:14 AM
External Data Range Properties ioates Excel VBA 1 December 3rd, 2004 08:03 AM
Excel VBA: Select range of data and plot chart? xitu Excel VBA 1 December 23rd, 2003 04:21 AM

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