Query by date

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

Join Date: Dec 2008
Posts: 21
Reputation: sackymatt is an unknown quantity at this point 
Solved Threads: 0
sackymatt sackymatt is offline Offline
Newbie Poster

Query by date

 
0
  #1
Oct 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 303
Reputation: TomW is on a distinguished road 
Solved Threads: 44
TomW TomW is offline Offline
Posting Whiz
 
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 42
Reputation: kplcjl is an unknown quantity at this point 
Solved Threads: 5
kplcjl kplcjl is offline Offline
Light Poster
 
1
  #3
Oct 30th, 2009
I second Tom's suggestion to use parameters. This assures the types are compatible and takes care of formatting as well.

Are you sure the datetimepicker will pick an exact date and time that you want? It's possible the query will never find the record even if it is formatted correctly.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC