以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]参数“Expression”不是有效值  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97115)

--  作者:huhu
--  发布时间:2017/3/6 14:57:00
--  [求助]参数“Expression”不是有效值
<WebMethod()>
    Public Function Detailedquery(ByVal scddhm As String, ByVal gdhh As String, ByVal ddh As String, ByVal ddhh As String, ByVal wlbm As String, ByVal kwlb As String, ByVal lhbbh As String, ByVal rjbb As String, ByVal startdate As String, ByVal enddate As String) As String
        Dim cnStr As String = "Data Source=172.16.11.201;Initial Catalog=songjiang;Integrated Security=False;User ID=sa;Password=bdcom103liujy;"
        Dim cn As New SqlClient.SqlConnection(cnStr)
        Dim strSql As String = ""
        cn.Open()
        Dim filter As String = "1=1"
        If ((scddhm = "null" Or scddhm = "") And gdhh > "") Or ((ddh = "null" Or ddh = "") And ddhh > "") Then
            Dim state As String = "工单行号必须与生产订单号码一起作为查询条件,订单行号必须与订单号一起作为查询条件。"
            Return state
        Else
            If scddhm = "null" Or scddhm = "" Then
                filter &= " and 1=1"
            ElseIf scddhm > "" Then
                filter &= " and Convert(varchar, 生产订单号码) = \'" & scddhm & "\'"
            End If
            If gdhh = "null" Or gdhh = "" Then
                filter &= " and 1=1"
            ElseIf gdhh > "" Then
                filter &= " and Convert(varchar, 工单行号) = \'" & gdhh & "\'"
            End If
            If ddh = "null" Or ddh = "" Then
                filter &= " and 1=1"
            ElseIf ddh > "" Then
                filter &= " and Convert(varchar, 订单号) = \'" & ddh & "\'"
            End If

            If ddhh = "null" Or ddhh = "" Then
                filter &= " and 1=1"
            ElseIf ddhh > "" Then
                filter &= " and Convert(varchar, 订单行号) = \'" & ddhh & "\'"
            End If

            If wlbm = "null" Or wlbm = "" Then
                filter &= " and 1=1"
            ElseIf wlbm > "" Then
                filter &= " and Convert(varchar, 物料编码) = \'" & wlbm & "\'"
            End If

            If lhbbh = "null" Or lhbbh = "" Then
                filter &= " and 1=1"
            ElseIf lhbbh > "" Then
                filter &= " and Convert(varchar, 两化表编号) = \'" & lhbbh & "\'"
            End If

            If rjbb = "null" Or rjbb = "" Then
                filter &= " and 1=1"
            ElseIf rjbb > "" Then
                filter &= " and Convert(varchar, 软件版本) = \'" & rjbb & "\'"
            End If

            If kwlb = "null" Or kwlb = "" Then
                filter &= " and 1=1"
            ElseIf kwlb > "" Then
                filter &= " and Convert(varchar, 库位类别) = \'" & kwlb & "\'"
            End If

            If startdate = "null" Or startdate = "" Then
                filter &= " and 1=1"
            ElseIf startdate > "" Then
                filter &= " and 入库时间 >=  \'" & startdate & "\'"
            End If

            If enddate = "null" Or enddate = "" Then
                filter &= " and 1=1"
            ElseIf enddate > "" Then
                filter &= "and 入库时间 <= \'" & enddate & "\'"
            End If

            strSql = "s elect * from [可用数量表]  where " & filter

            Dim adapter As New SqlClient.SqlDataAdapter(strSql, cn)
            Dim dt As New DataTable
            adapter.Fill(dt)
            cn.Close()
            Dim state As String = OrderQueryBLL.ConvertToJsonObject(dt)
            Return state
        End If
    End Function
当所有参数为空时,提示错误红色错误
System.ArgumentException: 参数“Expression”不是有效值。
   在 Microsoft.VisualBasic.Strings.Format(Object Expression, String Style)
   在 WebApplication4.OrderQueryBLL.GetWareRootWork(DataRow dr1) 位置 F:\\VS\\WebApplicationN\\WebApplication4\\OrderQueryBLL.vb:行号 51
   在 WebApplication4.OrderQueryBLL.ConvertToJsonObject(DataTable dataTable) 位置 F:\\VS\\WebApplicationN\\WebApplication4\\OrderQueryBLL.vb:行号 31
   在 WebApplication4.WebService1.Detailedquery(String scddhm, String gdhh, String ddh, String ddhh, String wlbm, String kwlb, String lhbbh, String rjbb, String startdate, String enddate) 位置 F:\\VS\\WebApplicationN\\WebApplication4\\WebService1.asmx.vb:行号 315
 
OrderQueryBLL.vb:行号 51---下面是51行的代码
Public Shared Function GetWareRootWork(ByVal dr1 As DataRow) As WareRootWork
        Dim rootWork As New WareRootWork(dr1("_Identify").ToString(), dr1("生产订单号码").ToString(), dr1("工单行号").ToString(), dr1("订单号").ToString(), dr1("订单行号").ToString(), dr1("物料编码").ToString(), dr1("软件版本").ToString(), dr1("两化表编号").ToString(), dr1("数量").ToString(), dr1("在库数量").ToString(), Format(dr1("入库时间"), "yyyy-MM-dd HH:mm:ss"))
        Return rootWork
    End Function

--  作者:有点色
--  发布时间:2017/3/6 15:48:00
--  

这样写,会报错

 

Dim t = DBNUll.value
Format(t, "yyyy-MM-dd HH:mm:ss")

 

要改成这样写

 

Dim t = DBNUll.value
If Typeof t Is dbnull Then
    msgbox("不行啊")
Else
    Format(t, "yyyy-MM-dd HH:mm:ss")
End If