PC Review


Reply
Thread Tools Rate Thread

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

 
 
steve-russell@hotmail.com
Guest
Posts: n/a
 
      16th Nov 2006
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 Removed)

 
Reply With Quote
 
 
 
 
RobinS
Guest
Posts: n/a
 
      17th Nov 2006
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.
-------------------------------------------

<steve-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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 Removed)
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datatable.Select() and datagrid results jcochran@rethinkllc.com Microsoft ADO .NET 4 23rd Aug 2005 01:11 AM
Display results in datagrid James Goodman Microsoft Dot NET Compact Framework 1 8th Jun 2005 06:57 AM
How do you display results of query in textbox =?Utf-8?B?a3JoYXJyaXNvbg==?= Microsoft Access 7 16th May 2005 05:54 PM
how do i display excel results in vb.net textbox bella Microsoft Excel Misc 0 7th Apr 2004 06:17 AM
Display SQL results in DataGrid Steven Smith Microsoft VB .NET 2 18th Dec 2003 04:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:16 PM.