Display SELECT results on two dates (datagrid and textbox in vb)

  • Thread starter Thread starter steve-russell
  • Start date Start date
S

steve-russell

I dont know why I am having so much problems with this. I cant find an
example anywhere.
I have a datagrid and I want to fill it using two textboxes, one with
start date and the other with end date. I've even tried to Dim
variables for the txtStartDate.Text and txtEndDate.Text and placed them
where the ? are but when I run it a green bar highlights the
..Fill(DataSet11) below and stops but I can place my cursor on the
variable and see the content (ie #3/12/2006# and #3/22/2006#) but will
not fill the datagrid.

The textboxes are named txtStartDate and txtEndDate

Me.OleDbSelectCommand1.CommandText = "SELECT Fname, Lname, Company,
EventName, EventDate FROM MasterDB WHERE (EventDate > ?) AND (EventDate
< ?)"


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
OleDbDataAdapter1.SelectCommand.Parameters("EventDate").Value =
txtStartDate.Text
OleDbDataAdapter1.SelectCommand.Parameters("EventDate").Value =
txtEndDate.Text
OleDbDataAdapter1.Fill(DataSet11)

Steve
(e-mail address removed)
 
I don't get the question mark thing. Are you trying to use
a parameterized query? Why are you setting the Event Date
to both values?

Are you constructing the query in the form? If so, try this:

Dim SqlString As String
SqlString = "SELECT FName, LName, Company EventName, EventDate " & _
" FROM MasterDB WHERE EventDate BETWEEN #" & txtStartDate.Text & _
"# AND #" & txtEndDate.Text & "#"
Me.OleDbSelectCommand1.CommandText = SqlString
Me.OleDbDataAdapter1.Fill(DataSet11)

If you are using MS Access, the delimiter is #. If you are using
just about any other database, the delimiter is a single quote.

SQLServer will take the dates in mm/dd/yy format. If you're using
SQLServer, you should use the SQL database connectivity stuff
(SQLDB) instead of OLEDB.

If your date field in the database has times in it, you will
want to do something like this:

" BETWEEN #" & txtStartDate.Text & " 00:00:00# AND #" & _
txtEndDate.Text & " 23:59:59#"

If you are using a different database, you need to heed the
format of your dates. For example, if you are using Oracle,
the dates *must* be in the format of dd-mmm-yyyy (like 14-Nov-2006).

Hope that helps.
Robin S.
 
Back
Top