HAI!
CAN ANYONE HELP ME TO RETREIVE DATA BETWEEN TWO DATES FROM MS-ACCESS USING VB.NET.

I HAVE TAKEN DATETIMEPICKER CONTROLS. THIS IS THE CODE . ITS RETURS ERROR.
PLEASE SOLVE THIS PROBLEM.
Imports System.Data.OleDb
Public Class Form7
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db2.mdb;")
Dim dataset1 As New DataSet()
Dim ddate1 As Date = DateTimePicker1.Text
Dim ddate2 As Date = DateTimePicker2.Text

'Dim sqlstring As String = "select * from enq1 where ddate >= '" & ddate1 & "' AND ddate <= '" & ddate2 & "'"
cmd = New OleDbCommand(sqlstring, con)
Dim oledbdataadapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(sqlstring, con)
con.Open()
oledbdataadapter1.Fill(dataset1, "enq1")
DataGridView1.DataSource = dataset1.Tables("enq1")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
End Sub


End Class

Recommended Answers

All 2 Replies

Without knowing which error you are getting it is hard to tell what to say, something to check though would be to make sure that you have the same format of date in your database as you are passing to it. That could cause a problem...

HAI!
CAN ANYONE HELP ME TO RETREIVE DATA BETWEEN TWO DATES FROM MS-ACCESS USING VB.NET.

I HAVE TAKEN DATETIMEPICKER CONTROLS. THIS IS THE CODE . ITS RETURS ERROR.
PLEASE SOLVE THIS PROBLEM.
Imports System.Data.OleDb
Public Class Form7
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db2.mdb;")
Dim dataset1 As New DataSet()
Dim ddate1 As Date = DateTimePicker1.Text
Dim ddate2 As Date = DateTimePicker2.Text

'Dim sqlstring As String = "select * from enq1 where ddate >= '" & ddate1 & "' AND ddate <= '" & ddate2 & "'"
cmd = New OleDbCommand(sqlstring, con)
Dim oledbdataadapter1 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(sqlstring, con)
con.Open()
oledbdataadapter1.Fill(dataset1, "enq1")
DataGridView1.DataSource = dataset1.Tables("enq1")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
con.Close()
End Sub


End Class

In Access you can use the DateDiff function and get dates. You can also use the same fucntion in VB.NET.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.