4 Replies - 9772 Views - Last Post: 07 October 2008 - 01:49 PM Rate Topic: -----

#1 noid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-June 08

Searching Date Range(Visual Basic Studio 2008)

Post icon  Posted 02 August 2008 - 11:50 PM

This is my first program and have absolutely no training in Visual Basic Studio 2008 so forgive me if I have miss something obvious.

In the code below Form3 has a StartDate(Date Time Picker1)and EndDate(Date Time Picker2) with a button1 which launches a Form4 containing a report.

I have been able to generate a report but it gives me everything in the database instead of range selected.

Any help would be greatly appreciated.

Please find code below

Thank you

Noid

Public Class Form3

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Form4.Show()

	End Sub

	Private Sub JCTableBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JCTableBindingNavigatorSaveItem.Click
		Me.Validate()
		Me.JCTableBindingSource.EndEdit()
		Me.TableAdapterManager.UpdateAll(Me.JCDataSet)

	End Sub

	Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'TODO: This line of code loads data into the 'JCDataSet.JCTable' table. You can move, or remove it, as needed.
		Me.JCTableTableAdapter.Fill(Me.JCDataSet.JCTable)

	End Sub


	Private Sub StartDateDateTimePicker_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles StartDateDateTimePicker.Enter

	End Sub

	Private Sub EndDateDateTimePicker_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles EndDateDateTimePicker.Enter

	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Searching Date Range(Visual Basic Studio 2008)

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Searching Date Range(Visual Basic Studio 2008)

Posted 03 August 2008 - 04:46 AM

It seems to be like you are doing the data fetching and filtering in form4, so we needs to see the code in "form4" to say something more.

Anyway one thing I can say in advance is that, using the "between" operator in your select statement will get you the data for a date range.
Was This Post Helpful? 1
  • +
  • -

#3 noid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-June 08

Re: Searching Date Range(Visual Basic Studio 2008)

Posted 03 August 2008 - 01:29 PM

View Postdineeshd, on 3 Aug, 2008 - 04:46 AM, said:

It seems to be like you are doing the data fetching and filtering in form4, so we needs to see the code in "form4" to say something more.

Anyway one thing I can say in advance is that, using the "between" operator in your select statement will get you the data for a date range.



Dineeshd,

Thank you for your reply.

The code to Form4 is below:

Public Class Form4

	Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'TODO: This line of code loads data into the 'JCDataSet.JCTable' table. You can move, or remove it, as needed.
		Me.JCTableTableAdapter.Fill(Me.JCDataSet.JCTable)

		Me.ReportViewer1.RefreshReport()
	End Sub
End Class



As you can see there is not much code.

Are you recommending:

1) I enter additional code into Form4?
2) Add a query into the Dataset (It is a bit confusing as there is two dates and would not know where to begin)?
3) Or add additional code to the Dataset (code below)?


Partial Class JCDataSet
	Partial Class JCTableDataTable

		Private Sub JCTableDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanging
			If (e.Column.ColumnName = Me.OccupiedNightsColumn.ColumnName) Then
				'Add user code here
			End If

		End Sub

	End Class

End Class

Namespace JCDataSetTableAdapters
	
	Partial Public Class JCTableTableAdapter
	End Class
End Namespace



Again, I apologise for what may appear as silly questions but I have only be teaching myself programming for a few months now.

Thank you

Noid
Was This Post Helpful? 0
  • +
  • -

#4 noid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-June 08

Re: Searching Date Range(Visual Basic Studio 2008)

Posted 08 August 2008 - 04:39 PM

No matter what I try I still receive all entries in the database in the report -

I thought this would be some what a common problem with a common solution but has been very difficult to research

Some one out there must know how to do it.


noid
Was This Post Helpful? 0
  • +
  • -

#5 MacAnimeGirl  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 282
  • Joined: 30-September 08

Re: Searching Date Range(Visual Basic Studio 2008)

Posted 07 October 2008 - 01:49 PM

View Postnoid, on 8 Aug, 2008 - 04:39 PM, said:

No matter what I try I still receive all entries in the database in the report -

I thought this would be some what a common problem with a common solution but has been very difficult to research

Some one out there must know how to do it.


noid



it looks like you haven't set the program up to look between those dates.

Try doing a command statement.

For access
Dim cmd as New OleDb.OleDbCommand
cmd.Command.Text = "Select * From [Table Name]  Where [Date Field Name from Table] Between #" _  
& startDate & "# AND #" & endDate & "#"



For SQL you'd only need to change what you dimmed cmd to be. It would be SQLClient.SQLCommand.

You'll need to pass your startDate Value and endDate Value into the that area.

Your code is a little hard for me to read, so it's a bit confusing. But this is something I know how to do! Lol. I just got done using this situation in a program I rewrote!

This post has been edited by MacAnimeGirl: 07 October 2008 - 01:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1