English 中文(简体)
有可能在dataview.rowfilter中使用两个参数吗?怎样
原标题:is it possible to use 2 parameters with dataview.rowfilter? How?
  • 时间:2011-05-24 12:58:40
  •  标签:
  • vb.net

它使用1个参数(i_index),但如果我也使用i_datum,我会得到一个错误,如:“从字符串”park_id=100“转换为类型Long无效。”

Public Function detail_kalender(ByVal i_index As Int16, ByVal i_datum As Date) As DataRowView
    Dim dv As DataView
    Dim anyrow As DataRowView
    dv = New DataView

    With dv

        .Table = myds.Tables("kalender")
        .AllowDelete = True
        .AllowEdit = True
        .AllowNew = True
        .RowFilter = "park_id = " & i_index And "datum =" & i_datum


    End With
    anyrow = dv.Item(0)  geeft de eerste rij van de dataview dv

      Simple bind to a TextBox control
    dv = mydt_parken.DefaultView
    Return anyrow
    dv.Dispose()
    dv = Nothing

End Function
问题回答

查看行筛选器的代码,它将转换为:

.RowFilter = "park_id = 100datum = something"

请注意park_id和next字段之间缺少空间。你还需要加上“和”(我想?)

尝试:

.RowFilter = String.Format("park_id = {0} and datum = {1}", i_index.Tostring, i_datum.ToString)

根据您的数据类型,您可能需要对此进行修改,以包括撇号(即更改为

... and datum = ** **{1}** ** 

如果是字符串)

编辑:回应您的评论。

查看本页了解一些有用的提示。对于日期,请使用#符号。

.RowFilter = String.Format("park_id = {0} and datum = #{1}#", i_index.Tostring, i_datum.ToString)

EDIT:响应您的第二条注释(formatException“字符串未被识别为有效的DateTime。”):

这有点棘手。我将列出一个可能的快速解决方案,但决不是最佳解决方案。

Dim customDateFormat As String = "MM/dd/yyyy hh:mm:ss"
.RowFilter = String.Format("park_id = {0} and datum >= #{1}# and datum <= #{2}#", 
                           i_index.ToString, 
                           New DateTime(i_datum.Year, i_datum.Month, i_datum.Day, 0, 0, 0).ToString(customDateFormat),
                           New DateTime(i_datum.Year, i_datum.Month, i_datum.Day, 23, 59, 59).ToString(customDateFormat))

基本上,当你将你的日期s与数据库中的日期时间进行比较时,你想忽略时间吗?(在这里做一个假设)。一种方法是将数据库数据与日期进行比较,确保日期在00:00 AM到23:59:59 PM之间。

我已经包含了一个customDateFormat字符串,如果需要,您可以篡改它,以反映您的区域设置。我知道日期常量忽略区域设置,但我不知道它在RowFilter中作为字符串做什么,也不知道数据库区域设置是否对它有任何影响。如果以上方法不起作用,你可以更改日期格式字符串以匹配你的区域设置,看看这是否有帮助。

请尝试使用:

.RowFilter = "park_id = " & i_index  & " And datum =" & i_datum




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签