Click here to Skip to main content
15,923,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
&<<code><code><code>

The following code does not return any values, can anyone help me? I have been struggling for an hour with this. Thanks in Advance.

VB
Dim conn As New OleDb.OleDbConnection
        Dim cmd As New OleDb.OleDbCommand
        Dim da As New OleDb.OleDbDataAdapter
        Dim dsLocal As New DataSet
        Dim salesFrom As Date = dtpFrom.Text
        Dim salesTo As Date = dtpTo.Text
        Dim FromDate As String = Format(salesFrom, "dd/MM/yyyy")
        Dim ToDate As String = Format(salesTo, "dd/MM/yyyy")

        Try


        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\mrs-v4\mrs-v4-" & LogOn.mDatabaseName & ".mdb"
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text

   <pre lang="vb">cmd.CommandText = "Select [docket#],consignmentID, date_sold, qty, amount, vat,[accsale#] From sale where consignmentID >=" & txtConsID_Sales.Text & " AND date_sold >= " & FromDate & " AND  date_sold <= " & ToDate

da.SelectCommand = cmd
dsLocal.Tables.Add("sample")
dsLocal.Tables("sample").Clear()
conn.Open()
da.SelectCommand.ExecuteNonQuery()
da.Fill(dsLocal.Tables("sample"))
conn.Close()

Me.dgvSales.DataSource = dsLocal.Tables("sample")

conn.Dispose()

ds = dsLocal

da.Dispose()
dsLocal.Dispose()
cmd.Dispose()
Catch ex As Exception

End Try
End Sub
Posted
Updated 29-Nov-10 21:25pm
v2

1 solution

If you are sure you have data in between those dates provided then May be you can try the following
1. Convert your dates into YYYY-MM-DD format instead of DD/MM/YYYY
2. Try the following query

Select [docket#],consignmentID, date_sold, qty, amount, vat,[accsale#] From sale where consignmentID >=" & txtConsID_Sales.Text & " AND date_sold >= CDATE('" & FromDate & "') AND  date_sold <= CDATE('" & ToDate & "')"
 
Share this answer
 
Comments
Thabo Pali 30-Nov-10 4:40am    
Thanks a lot it worked. WOW!

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