p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2006, 11:18 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display data within data range?

Hi,

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
textboxes.

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
                    command.SelectCommand.Parameters.Add(param1)
        Dim param2 As New SqlParameter("@Date2", SqlDbType.DateTime)
                    param1.Value = Date2.Text
                    command.SelectCommand.Parameters.Add(param2)

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


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.


Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old June 9th, 2006, 11:34 AM
Friend of Wrox
Points: 1,880, Level: 17
Points: 1,880, Level: 17 Points: 1,880, Level: 17 Points: 1,880, Level: 17
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Jul 2003
Location: , , .
Posts: 556
Thanks: 6
Thanked 1 Time in 1 Post
Default

You're syntax for using BETWEEN is not correct.

Here's an example:

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

This syntax is in the BOL.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old June 9th, 2006, 04:06 PM
Banned
Points: 344, Level: 6
Points: 344, Level: 6 Points: 344, Level: 6 Points: 344, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2006
Location: New Delhi,India.
Posts: 76
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 Send a message via Skype™ to anujrathi
Default

use
param1.Value = Convert.ToDateTime(Date1.Text)
&
param2.Value = Convert.ToDateTime(Date2.Text)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
varying data range stealthdevil Excel VBA 6 July 27th, 2007 03:30 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 08: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



All times are GMT -4. The time now is 08:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc