【问题标题】:ASP.NET DataContext issueASP.NET 数据上下文问题
【发布时间】:2012-06-22 19:08:43
【问题描述】:

我正在调用我的 DataContext 对象的 ExecuteQuery 方法。结果,我希望每一行都有一个字符串和一个整数,但是当我运行 ToList 函数时,我的所有值都是空的和 0。我所有的结果都应该是不同的字符串和数字。如果我直接运行它,我的查询运行完美,但 ExecuteQuery 返回垃圾而不是有效结果。这可能是什么原因?

提前谢谢你。

编辑:

public function something as List(of Pair(of String, Integer))
            Dim c As TTDataContext = ContextFactory.CreateDataContext()
            Dim startValueLen = CStr(StartValue).Length
            Dim query As String = "select top " & CStr(Limit) & " case " &
                                                                   " when WONum like '0000%' then SUBSTRING(WONum, 5, Len(WONum) - 4) " &
                                                                   " when WONum like '000%' then SUBSTRING(WONum, 4, Len(WONum) - 3) " &
                                                                   " when WONum like '00%' then SUBSTRING(WONum, 3, Len(WONum) - 2) " &
                                                                   " when WONum like '0%' then SUBSTRING(WONum, 2, Len(WONum) - 1) " &
                                                                   " else WONum " &
                                                                   " end as retVal, " &
                                                                   " case " &
                                                                   " when WONum like '0000%' then 1 " &
                                                                   " when WONum like '000%' then 2 " &
                                                                   " when WONum like '00%' then 3 " &
                                                                   " when WONum like '0%' then 4 " &
                                                                   " else LEN(WONum) " &
                                                                   " end as retLen " &
                                                                   " from TblWorkOrder " &
                                                                   " where CompanyID = " & CStr(CompanyID) & " and LEN(WONum) >= " & CStr(startValueLen) & " and (WONum > '" & CStr(StartValue) & "' or LEN(WONum) > " & CStr(startValueLen) & ") " &
                                                                   " order by retLen, retVal"
            Dim temp = c.ExecuteQuery(Of Pair(Of String, Integer))(query)
            Return temp.ToList
End Function

【问题讨论】:

  • 也许给我们看一些代码?你希望我怎么回答这个问题???
  • 感谢您的 cmets,我已经发布了一个非常简单的代码,因为我的查询大约有 1500 个字符。
  • 请注意您的标签选择。在超过 300 万个问题中,这将是唯一一个标记为 vb 的堆栈溢出问题。这应该是一个巨大的指标,表明有问题。相反,使用更具体的标签,如 vb.net、vbscript、vb6 或 vba
  • 还有:你知道什么是sql注入漏洞吗?看起来你已经过去了。

标签: asp.net vb.net datacontext


【解决方案1】:

问题的原因是我的 Pair 类具有 First 和 Second 属性,而我没有将结果返回为 First 和 second。所以这个问题的解决方法是将第一个值返回为 First,将第二个值返回为 Second 而不是 retVal 和 retLen。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2023-03-13
    相关资源
    最近更新 更多