vb.net 2010 MS Access 2013日期之间的搜索错误

问题描述:

我正在使用VS2010和Microsoft Access Database 2013,其中每一行(Record)都有一个名为ActionStartDate的日期字段,我想查看日期位于用户使用两个DateTimePickers确定的两个日期之间的所有记录,但是在应用程序调试之前有一条错误消息,其中包含以下错误更正选项:



第一个

'公共可覆盖重载的参数太多函数



SearchBetweenDates4ActionStartDate(数据表为GSKAction数据库数据集actionslog数据表)为整数'



第二个



为'GSK员工操作管理器中的'SearchBetweenDates4ActionStartDate生成方法存根.GSK EmployeeActionsDB数据集表adapters.actionslogtable适配器'



我的代码如下。



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.

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





我的查询如下:



方法名称:SearchBetweenDates4ActionStartDate





And my Query is as follows:

Method Name: SearchBetweenDates4ActionStartDate

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.

您不能在SQL语句中使用DateTimePicker控件。该语句只是一个发送到SQL服务器的文本字符串,它不知道DateTimePicker1。[Value]是什么意思。



你有添加DateTimePicker值应该去的参数,然后将参数值设置为DateTimePicker控件返回的值。



阅读使用此列表 [ ^ ]。
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[^].


如果查询是针对TableAdapter然后它将无法工作,则需要替换DateTimePicker1.Value和DateTimePicker2.Value带有?标记where条件的每个部分。这将使查询构建器为两个参数生成一个Fill方法,然后传入DateTimePickers中的值。
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.