access中定义了一个模块(方法formatMph)
在ACCESS的查询中使用该方法select formatMph([tableCustom.UAddss]) from tableCustom 时正常不报错.但在winform下调用此"查询"时出错,提示"formatMph()方法未定义.这是什么原因?如何解决?

解决方案 »

  1.   

    dbo.formatMph([tableCustom.UAddss]) 看看
      

  2.   

    access中定义了一个模块(方法formatMph)
    Option Compare DatabasePublic Function formatMph(strMph)
    Dim d As String
    Dim dy As String
    Dim h As String
    Dim tmp
    tmp = Split(strMph, "-", -1, 1)If (Len(tmp(0)) = 2) Then
        If (Mid(tmp(0), 1, 1) = "0") Then
           d = Mid(tmp(0), 2, 1)
        Else
            d = tmp(0)
        End If
    Else
        d = tmp(0)
    End IfIf (Len(tmp(1)) = 2) Then
        If (Mid(tmp(1), 1, 1) = "0") Then
           dy = Mid(tmp(1), 2, 1)
        Else
            dy = tmp(1)
        End If
    Else
        dy = tmp(1)
    End If
        
    If (Len(tmp(2)) = 2) Then
        If (Mid(tmp(2), 1, 1) = "0") Then
           h = Mid(tmp(2), 2, 1)
        Else
            h = tmp(2)
        End If
    Else
        h = tmp(0)
    End If
        
    formatMph = d + "-" + dy + "-" + hEnd FunctionAccess中查询的名字为:queryAddress.语句为:select formatMph([tableCustom.UAddss]) from tableCustom 
    winform 下利调用此函数返回DatSet
    代码片断:
                string sql = "select * from queryAddress";
                OleDbConnection oc = ClassConnect.getConnect();
                OleDbCommand ocmd = new OleDbCommand(sql, oc);
                DataSet ds = new DataSet();
                OleDbDataAdapter oda = new OleDbDataAdapter(ocmd);
                oda.Fill(ds, "tableHz");
                return ds;
    提示formatMph()方法未定义.好象C#下不能识别Access中自定义的方法
    按楼上的办法odb.formMph()在Access中就通不过.
      

  3.   

    原因找到了.ACCESS里的自定义函数根本不被其它环境支持.另想他法了.
    结贴