View Single Post
  #1 (permalink)  
Old June 9th, 2006, 11:18 AM
ktsis ktsis is offline
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

Reply With Quote