Click here to Skip to main content
16,020,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Guys,

I want this piece of code to display the current pick date in the date picker but it won't but it display all the transaction if I choose the other check box but when I want to choose the bydate checkbox it won't display the current pick date can anyone help me with this please :D
VB
ElseIf Me.ListBox1.Text = "Stock - IN" Then
          If Me.chkAll.CheckState = CheckState.Checked Then
              xSQL = "SELECT * FROM po"
          Else
              xSQL = "SELECT * FROM po WHERE PODate>" & "#" & Format(Me.dtFrom.Value, "MM/dd/yyyy") & "#" & "" & _
                  " AND PODate<" & "#" & Format(Me.dtTo.Value, "MM/dd/yyyy") & "#" & ";"
          End If
          If frmMain.PrintPO(xSQL) = True Then
              frmReportViewer.strReport = "PO"
              frmReportViewer.Show()
          End If
          
      ElseIf Me.ListBox1.Text = "Stock - OUT" Then
          If Me.chkAll.CheckState = CheckState.Checked Then
              xSQL = "SELECT * FROM sales"
          Else
              xSQL = "SELECT * FROM sales WHERE SalesDate>" & "#" & Format(Me.dtFrom.Value, "MM/dd/yyyy") & "#" & "" & _
                  " AND SalesDate<" & "#" & Format(Me.dtTo.Value, "MM/dd/yyyy") & "#" & ";"
          End If
Posted
Updated 10-Sep-10 6:08am
v2
Comments
Sandeep Mewara 10-Sep-10 12:08pm    
Formatted your code piece(use PRE tags for that), couldn't get what you were trying to ask.

1 solution

A couple of things;

1) I have been troubled with dates in the past when working with SQL queries, so I always past dates in like '2010-Sep-10'

2) I notice in the SQL text you are adding a "" to the right?

Have you dumped the SQLtext to the output window to see exactly what the query text looks like?

I would write the statement above as;

SQL
xSQL = "SELECT * FROM sales WHERE SalesDate > '" & Format(Me.dtFromValue, "yyyy-MMM-dd") & "' AND SalesDate < '" & Format(Me.dtTo.Value, "yyyy-MMM-dd") & "';"


Also, you may want to look at creating paramaterised queries.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900