Foxtable(狐表)用户栏目专家坐堂 → [求助]参数“Expression”不是有效值


  共有2934人关注过本帖树形打印复制链接

主题:[求助]参数“Expression”不是有效值

帅哥哟,离线,有人找我吗?
huhu
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1182 积分:8225 威望:0 精华:0 注册:2015/3/30 10:44:00
[求助]参数“Expression”不是有效值  发帖心情 Post By:2017/3/6 14:57:00 [只看该作者]

<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

 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By: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


 回到顶部