Question Search from database according to from date to end date

swethajain

Well-known member
Joined
Feb 1, 2010
Messages
48
Programming Experience
Beginner
Hi,
I want a search condition like if i enter a from date to some other date in 2 datetime pickers, the records from both the dates should be displayed in the datagrid view.Can anyone please tell me the source code? Please.........

Thanks,
Swetha.
 
error in retrieving records between dates

Hi,
i have written code to retrieve records from database when date is between some 2 dates and username should be same, the error is when i want to display records between 4th feb to 6th feb then only 5th & 6th feb records are only coming, the code is,
Imports System.Data.OleDb
Public Class Search2
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand

Private Sub Search2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dg1.Visible = "False"

End Sub

Private Sub bt_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Search.Click
Try
Dim fdt As Date = dtp_Fromdate.Text
Dim tdt As Date = dtp_Todate.Text
Dim us As String = txtbx_Username.Text
myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='h:\info2.mdb'")
Dim strQry As String = "select [ID],[Dt],[Res],[Construction Package],[Region],[Trade],[Location],[Network Name],[Task],[Progress],[Duration],[Assumptions] from Record where Dt between '" & fdt & "' and '" & tdt & "' and Res = '" & us & "'"
myConnection.Open()
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(strQry, myConnection)
da.Fill(ds, "Record")
If (ds.Tables(0).Rows.Count > 0) Then
dg1.DataSource = ds
dg1.DataMember = "Record"
dg1.Visible = "true"
Else
dg1.Visible = "false"
Label1.Text = "No Records"
End If
myConnection.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
End Class

Thanks,
Swetha.
 
Hi,
I want a search condition like if i enter a from date to some other date in 2 datetime pickers, the records from both the dates should be displayed in the datagrid view.Can anyone please tell me the source code? Please.........

Thanks,
Swetha.

DW2 link inm my signature, first do Creating a Simple Data App
Then do Creating a Form to Search Data

Please make your database columns a DATE type, not a string, that you put "12-nov-2009"

Then do your search as:
SELECT * FROM table WHERE datecol BETWEEN ? AND ?

(or use @names for SQLserver parameters or :names for oracle parameters)
If you dont know what an sql parameter is read the PQ link in my signature

Add 1 to the end date if your date column in the DB contains a time as well:

tableAdapter.FillByDates(myDatepicker1.Value.Date, myDatepicker2.Value.Date.AddDays(1))

If you find results from midnight on day 2 being returned, make your SQL:

SELECT * FROM table WHERE datecol >= ? AND datecol < ?
 
Back
Top