Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:09:33+00:00 2026-05-27T11:09:33+00:00

i need to select some records from table Tr_cashbook between two date. the date

  • 0

i need to select some records from table Tr_cashbook between two date. the date field is newdt in which i need to compare data and the records should be shown in crystal report named rptCash2. the newdt field has datetime property. here is the code on the command button

    bdcon.Open()

    Dim QueryString As String
                QueryString = "Select * from Tr_Cashbook where (Cast(newdt as date)>=  " & DateTimePicker1.Value.ToString("yyyy-MM-dd") & ") and (Cast(newdt as date) <= " & DateTimePicker2.Value.ToString("yyyy-MM-dd") & ")"

    Dim Adapter As SqlDataAdapter = New SqlDataAdapter(QueryString, bdcon)
    Dim ds As DataSet = New DataSet()
    Adapter.Fill(ds, "Tr_Cashbook")

    rptCash2.Load()
    rptCash2.SetDataSource(ds)
    CrystalReportViewer1.ReportSource = rptCash2

  bdcon.Close()

but this is not working
when i press the command button it gives error as operand type clash: date is incompatible with int. i am not able to find out where i go wrong . help me with this..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:09:34+00:00Added an answer on May 27, 2026 at 11:09 am

    Use parameters instead of hard-coded sql string.

    Your parameterized query shoud be:

     QueryString = "Select * from Tr_Cashbook where newdt>=@date1 and 
         newdt<= @date2"
    
     Dim Cmd as new SqlCommand(QueryString,bdcon)
     Cmd.Parameters.Add("@date1",SqlDbType.Date).Value=DateTimePicker1.Value
     Cmd.Parameters.Add("@date2",SqlDbType.Date).Value=DateTimePicker2.Value
    
     Dim Adapter As SqlDataAdapter = New SqlDataAdapter(Cmd)
     Dim ds As DataSet = New DataSet()
     Adapter.Fill(ds, "Tr_Cashbook")
    

    You may use BETWEEN AND syntax:

    QueryString = "Select * from Tr_Cashbook where newdate BETWEEN  @date1 AND @date2"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to select some records from a table where a column value is
I need a select from table which does not have column that tells when
I need to select some rows from second table and concatenate them in comma-separated
I need to take some data from one table (and expand some XML on
I need to get around 50k-100k records from a table. Two of the fields
I need to select some values from a table to be updated, and then
I need some help with SQL Query. I am trying to select all records
I need to select a bunch of data into a temp table to then
i would like to select * from table where dates between (some_date and another_date)
i need to export data from a table to a csv. i have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.