| | |
Query by date
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 21
Reputation:
Solved Threads: 0
Hi all,
I have a small problem that i cant figure out. i have a program that i want when a user select a date from a datetimepicker, it filters evrything from the datagridview that are for that date..
Hare is the code i have
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oledb As System.Data.OleDb.OleDbConnection
oledb = New System.Data.OleDb.OleDbConnection()
oledb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CMRS.mdb;Persist Security Info=True"
oledb.Close()
oledb.Open()
Try
Dim da As New OleDb.OleDbDataAdapter("Select * FROM Medical WHERE DateAttended= " & DtDate.Text, oledb)
Dim ds As New DataSet
da.Fill(ds)
'set filter to view only medical records of certain Student
medicalFilter(ds.Tables(0).Rows(0)(0))
oledb.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
it returns an error. No data at position 0
PLEASE help ASAP
I have a small problem that i cant figure out. i have a program that i want when a user select a date from a datetimepicker, it filters evrything from the datagridview that are for that date..
Hare is the code i have
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oledb As System.Data.OleDb.OleDbConnection
oledb = New System.Data.OleDb.OleDbConnection()
oledb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CMRS.mdb;Persist Security Info=True"
oledb.Close()
oledb.Open()
Try
Dim da As New OleDb.OleDbDataAdapter("Select * FROM Medical WHERE DateAttended= " & DtDate.Text, oledb)
Dim ds As New DataSet
da.Fill(ds)
'set filter to view only medical records of certain Student
medicalFilter(ds.Tables(0).Rows(0)(0))
oledb.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
it returns an error. No data at position 0
PLEASE help ASAP
•
•
Join Date: Sep 2009
Posts: 303
Reputation:
Solved Threads: 44
1
#2 Oct 29th, 2009
If you use the Code icon at the text area toolbar it will format your code for easier understanding here on the site.
Im not sure why your closing your connection before you even open it but either way both open & close calls are not needed. When you use a DataAdapter, it will automatically open & close the connection when you call the fill or update methods.
With Access you want to enclose your dates with the # symbol as you would quotes for strings. Since this is a date I would also suggest converting the text value of the textbox to an actual Date datatype. However I would suggest not concatenating your query string and instead use Parameter's to pass your value.
Im not sure why your closing your connection before you even open it but either way both open & close calls are not needed. When you use a DataAdapter, it will automatically open & close the connection when you call the fill or update methods.
With Access you want to enclose your dates with the # symbol as you would quotes for strings. Since this is a date I would also suggest converting the text value of the textbox to an actual Date datatype. However I would suggest not concatenating your query string and instead use Parameter's to pass your value.
![]() |
Similar Threads
- Tell me query about date (PHP)
- How to create query with date range and interval? (MS SQL)
- Verifying data entered in the date field components (Java)
- Update Query is not Working.. (PHP)
- urgent reply.. mysql bug... about queries date using MySQL (MySQL)
- query a date format within an input box (MS Access and FileMaker Pro)
- date comparison (JSP)
Other Threads in the VB.NET Forum
- Previous Thread: FlatStyle
- Next Thread: Hidden column in ListBox
| Thread Tools | Search this Thread |
.net 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dropdownlist excel fade file-dialog folder ftp generatetags google gridview hardcopy image images input insert intel internet listview mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print problem problemwithinstallation project remove save searchbox searchvb.net select serial server shutdown soap survey table tcp temperature text textbox timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





