Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VS2010 and Microsoft Access Database 2013 in which each row (Record) has a Date Field called ActionStartDate, I want to view all the records for which the date lies between two dates which the user determines using two DateTimePickers , but there is an error message before the application debugging with the following error correction options:

The first
Too many arguments to 'public overridable overloads function

SearchBetweenDates4ActionStartDate (datatable as GSKAction DB dataset actionslog datatable) as integer'

The second

Generate method stub for 'SearchBetweenDates4ActionStartDate in 'GSK Employee Actions Manager.GSK EmployeeActionsDB Dataset table adapters.actionslogtable adapter'

My code is below.

VB
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim Search1 As Date = DateTimePicker1.Value.ToShortDateString
        Dim Search2 As Date = DateTimePicker2.Value.ToShortDateString

        Me.ActionsLogTableAdapter.SearchBetweenDates4ActionStartDate(Me.GSKactionsDBDataSet.ActionsLog, Search1, Search2)
        Form48.MdiParent = Form27
        Form48.Show()
        Form48.ActionsLogTableAdapter.SearchBetweenDates4ActionStartDate(Form48.GSKactionsDBDataSet.ActionsLog, Search1, Search2)

    
    End Sub


And my Query is as follows:

Method Name: SearchBetweenDates4ActionStartDate

SQL
SELECT        ID, ActionReferance, ActionDescription, ActionSite, ActionCategory, ActionImportance, ActionAccountability, ActionProgressStatus, ActionClosurestatus, ActionDoneBy, 
                         ActionComment, ActionYear, ActionStartDate, PlannedClosureDate, RealClosureDate, ActualClosureDuration, PlannedClosureDuration
FROM            ActionsLog
WHERE        (ActionStartDate BETWEEN DateTimePicker1.[Value] AND DateTimePicker2.[Value])


Thanks for any help.
Posted
Updated 13-Sep-15 14:23pm
v3

You cannot use your DateTimePicker controls in the SQL statement. The statement is just a text string that is sent to the SQL server and it doesn't have a clue what "DateTimePicker1.[Value]" means.

You have to add parameters where your DateTimePicker values should go and then set the parameter values to the values returned by the DateTimePicker controls.

Read up on using parameterized queries from this list[^].
 
Share this answer
 
Comments
Sherif Adely 14-Sep-15 14:27pm    
Thanks alot Dave :)
Maciej Los 14-Sep-15 14:53pm    
5ed!
If the query is for a TableAdapter then it will not work, you need to replace DateTimePicker1.Value and DateTimePicker2.Value with a ? mark for each part of the where condition. This will have the query builder generate a Fill method for two parameters then pass in the values from the DateTimePickers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900