我希望按日期和月份过滤数据,但不包括年份。例如,我想在9月份找到第1天到第7天,所以我做的就像是
Private Sub ButtonFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonFilter.Click
Dim sdate As Date = dtpfrom.Value
Dim edate As Date = dtpto.Value.AddDays(+1)
Try
con = New OleDbConnection(cs)
con.Open()
cmd = New OleDbCommand("SELECT ID, SerialNo as [Serial No], NamaLengkapdanBaptis as [Nama Lengkap], JenisKelamin as [Jenis Kelamin], NoKTP as [Nomor KTP], TempatLahir as [Tempat Lahir], TanggalLahir as [Tanggal Lahir], GolonganDarah as [Golongan Darah], AlamatLengkap as [Alamat Lengkap], NoTelp as [Nomor Telepon], PendidikanUmum as [Pendidikan Umum], IjazahTahun as [Pendidikan Umum Berijazah Tahun], PendidikanAlkitab as [Pendidikan Alkitab], IjazahAlkitabTahun as [Alkitab Berijazah Tahun], TrainingEquipping as [Training & Equipping], Pekerjaan as [Pekerjaan], NamaPerusahaan as [Nama Perusahaan], AlamatTempatKerja as [Alamat Perusahaan], TelpKantor as [Telepon Kantor], BaptisSelam as [Baptis Selam], TempatatauGereja as [Tempat atau Gereja], PelayanandiGereja as [Pelayanan di Gereja], PelayananSebagai as [Sebagai], TempatNikah as [Tempat Nikah], TanggalNikah as [Tanggal Nikah], NamaAyah as [Nama Ayah], NamaIbu as [Nama Ibu],FotoProfil as [Foto Profil], NamaLengkapdanBaptisSI as [Nama Lengkap Istri atau Suami], JenisKelaminSI as [Jenis Kelamin Istri atau Suami], NoKTPSI as [Nomor KTP Istri atau Suami], TempatLahirSI as [Tempat Lahir Istri atau Suami], TanggalLahirSI as [Tanggal Lahir Istri atau Suami], GolonganDarahSI as [Golongan Darah Istri atau Suami], AlamatSI as [Alamat Istri atau Suami], NoTelpSI as [No Telepon Istri atau Suami], PendidikanUmumSI as [Pendidikan Umum Istri atau Suami], IjazahTahunSI as [Berijazah Tahun Istri atau Suami], PendidikanAlkitabSI as [Pendidikan Alkitab Istri atau Suami], IjazahAlkitabTahunSI as [Pendidikan Alkitab Berijazah Tahun], TrainingEquippingSI as [Training & Equipping Istri atau Suami], PekerjaanSI as [Pekerjaan Istri atau Suami], NamaPerusahaanSI as [Nama Perusahaan Istri atau Suami], AlamatTempatKerjaSI as [Alamat Perusahaan Istri atau Suami], TelpKantorSI as [Telepon Kantor Istri atau Suami], BaptisanSelamSI as [Baptisan Selam Istri atau Suami], TempatatauGerejaSI as [Tempat atau Gereja Istri atau Suami], PelayanandiGerejaSI as [Pelayanan di Gereja Istri atau Suami], PelayananSebagaiSI as [Istri atau Suami Sebagai], NamaAyahSI as [Nama Ayah Istri atau Suami], NamaIbuSI as [Nama Ibu Istri atau Suami], FotoProfilSI as [Foto Istri atau Suami], NamaAnak1 as [Nama Anak 1], TanggalLahirAnak1 as [Tanggal Lahir Anak 1], SekolahAnak1 as [Sekolah Anak 1], BaptisanAnak1 as [Baptisan Anak 1], FotoProfilAnak1 as [Foto Profil Anak 1], NamaAnak2 as [Nama Anak 2], TanggalLahirAnak2 as [Tanggal Lahir Anak 2], SekolahAnak2 as [Sekolah Anak 2], BaptisanAnak2 as [Baptisan Anak 2], FotoProfilAnak2 as [Foto Profil Anak 2], NamaAnak3 as [Nama Anak 3], TanggalLahirAnak3 as [Tanggal Lahir Anak 3], SekolahAnak3 as [Sekolah Anak 3], BaptisanAnak3 as [Baptisan Anak 3], FotoProfilAnak3 as [Foto Profil Anak 3], NamaAnak4 as [Nama Anak 4], TanggalLahirAnak4 as [Tanggal Lahir Anak 4], SekolahAnak4 as [Sekolah Anak 4], BaptisanAnak4 as [Baptisan Anak 4], FotoProfilAnak4 as [Foto Profil Anak 4], NamaAnak5 as [Nama Anak 5], TanggalLahirAnak5 as [Tanggal Lahir Anak 5], SekolahAnak5 as [Sekolah Anak 5], BaptisanAnak5 as [Baptisan Anak 5], FotoProfilAnak5 as [Foto Profil Anak 5], CscArea as [CSC Area], NoCsc as [Nomor CSC], NamaGembalaArea as [Nama Gembala Area], NamaGembalaCsc as [Nama Gembala CSC] from tb_daftarjemaat WHERE [TanggalLahir] BETWEEN #" & sdate & "# AND #" & edate & "#", con)
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "tb_daftarjemaat")
DataGridView2.DataSource = myDataSet.Tables("tb_daftarjemaat").DefaultView
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
但这不是我想要的理想结果