Click here to Skip to main content
15,907,120 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have problem in accessing data for a week or month using a datetimepicker. please tell me the query to access only some specific data i.e. particular week or particular month's record's.
Posted
Updated 11-Jun-11 1:44am
v2
Comments
Karwa_Vivek 11-Jun-11 7:57am    
please post your code
what you have tried so far.
So that we could suggest you something

Try:
SELECT * FROM myTable WHERE date>='2011-04-01" AND date <'2011-05-01'
 
Share this answer
 
Comments
OriginalGriff 11-Jun-11 9:09am    
Which returns a date/time? So you could use that?
I assume you have two datetimepicker
Try this on you Search Button Click Event
Dim sd As New SqlDataAdapter("Select * From table where DateOfEntry_From='" + dtp.Text.ToString() + "' and DateOfEntry_To='" + dtp2.Text.ToString() + "'", myCon.con())
        Dim dt As New DataTable
        sd.Fill(dt)
        If dt.Rows.Count > 0 Then
            dgV.DataSource = dt
        Else
            dgV.DataSource = Nothing
            MessageBox.Show("No data found ")
        End If

Implement as per your requirement
 
Share this answer
 
Comments
Jacson234 11-Jun-11 9:14am    
My code is:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
Dim cmb As String
'cmb = DateTimePicker1.Value.ToString("yyyy -MM-dd")
cmb = DateTimePicker1.Value.ToString("dd-MM-yyyy")
ds.Clear()
da = New OleDb.OleDbDataAdapter("Select * from Sale where Dat=#" & cmb & "#", con)
da.Fill(ds, "Tab")
con.Close()
DataGridView1.DataSource = ds.Tables("Tab").DefaultView
DataGridView1.Show()
End If
If RadioButton2.Checked = True Then
Dim mnth As String
mnth = DateTimePicker1.Value.ToString("dd-MM-yyyy")
mnth = DatePart(DateInterval.Month, DateTimePicker1.Value)
'mnth = DatePart("m", Dat, DateTimePicker1.Value)
'MsgBox(mnth)
ds2.Clear()
da1 = New OleDb.OleDbDataAdapter("Select * from Sale where Dat=#" & mnth & "#", con)
'da1 = New OleDb.OleDbDataAdapter("Select * from Sale where Datpart("m", Dat)=datetimepicker1.value, con)
da1.Fill(ds2, "Tab")
con.Close()
DataGridView1.DataSource = ds2.Tables("Tab").DefaultView
DataGridView1.Show()

End If
End Sub
Karwa_Vivek 11-Jun-11 9:37am    
you are using a long route

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