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

June 9th, 2006, 11:18 AM
|
|
Registered User
|
|
Join Date: May 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

June 9th, 2006, 11:34 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Location: , , .
Posts: 556
Thanks: 6
Thanked 1 Time in 1 Post
|
|
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.
|

June 9th, 2006, 04:06 PM
|
|
Banned
|
|
Join Date: Apr 2006
Location: New Delhi,India.
Posts: 76
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
use
param1.Value = Convert.ToDateTime(Date1.Text)
&
param2.Value = Convert.ToDateTime(Date2.Text)
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |