Retreive Data Between Two Dates From Ms-access Using Vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 2
Reputation: nsm_madhavi is an unknown quantity at this point 
Solved Threads: 0
nsm_madhavi nsm_madhavi is offline Offline
Newbie Poster

Retreive Data Between Two Dates From Ms-access Using Vb.net

 
0
  #1
Feb 13th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 49
Reputation: Mr.Wobbles is an unknown quantity at this point 
Solved Threads: 2
Mr.Wobbles Mr.Wobbles is offline Offline
Light Poster

Re: Retreive Data Between Two Dates From Ms-access Using Vb.net

 
0
  #2
Feb 15th, 2008
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...
Mr.Wobbles~
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 65
Reputation: SolTec is an unknown quantity at this point 
Solved Threads: 4
SolTec SolTec is offline Offline
Junior Poster in Training

Re: Retreive Data Between Two Dates From Ms-access Using Vb.net

 
0
  #3
Feb 21st, 2008
Originally Posted by nsm_madhavi View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC