Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 获得;多步骤操作产生的错误“;在ASP经典中使用合并数据集函数_Sql Server_Asp Classic_Ado - Fatal编程技术网

Sql server 获得;多步骤操作产生的错误“;在ASP经典中使用合并数据集函数

Sql server 获得;多步骤操作产生的错误“;在ASP经典中使用合并数据集函数,sql-server,asp-classic,ado,Sql Server,Asp Classic,Ado,我正在使用一个函数来合并一系列记录集,这些记录集是由循环中调用的存储过程生成的。我以前在其他存储过程案例中使用过此函数,但它从未产生过此问题。 我在网上做的研究基本上指出了两个原因之一: 1) 我正在尝试更新或在SQL Server 2005表中插入格式不正确的日期/时间值 2) 例如,我试图将CHAR(60)字符串插入CHAR(50)字段 原因一在这里不适用,因为我没有使用日期(至少是日期时间格式)。 原因二似乎是最可能的问题。因此,我做了一系列的响应。Write()吐出objField.Na

我正在使用一个函数来合并一系列记录集,这些记录集是由循环中调用的存储过程生成的。我以前在其他存储过程案例中使用过此函数,但它从未产生过此问题。 我在网上做的研究基本上指出了两个原因之一: 1) 我正在尝试更新或在SQL Server 2005表中插入格式不正确的日期/时间值 2) 例如,我试图将
CHAR(60)
字符串插入
CHAR(50)
字段

原因一在这里不适用,因为我没有使用日期(至少是日期时间格式)。 原因二似乎是最可能的问题。因此,我做了一系列的
响应。Write()
吐出
objField.Name
objField.Type
objField.ActualSize
,如果是数值字段,则吐出
objField.Precision
objField.NumericScale

假设在查询发生在同一时间段但处于两种不同状态的值时,调用存储SQL过程两次。我在ASP页面中的循环对状态列表中的每个状态都执行一个循环,并为状态列表中的每个元素调用存储过程。然后调用mergeRecordset函数,使其将两个结果合并为一个结果。一般规则是,每个结果集中列的数据类型和大小必须相同。通过我的
Response.Write()
检查两个数据集中返回的每一列,我发现它们是相同的。进行检查时,我还发现它在第一列(数值列)上断裂。之前的列都是
CHAR
VARCHAR

出现这个错误还有其他原因吗

下面是我如何调用记录合并函数的。
oQueryResult
将成为最终输出(组合记录)
objSingleRS
是存储过程返回的结果集

If oQueryResult Is Nothing Then
    Set oQueryResult = objSingleRS
Else
    Set oQueryResult = MergeRecordSets(Array(oQueryResult, objSingleRS))
End If
这里是合并函数。代码中断的行标记在下面

Function MergeRecordSets(arrRecordsets)
    Dim x, y, objCurrentRS
    Dim objMergedRecordSet, objField, blnExists
    Set objMergedRecordSet = Server.CreateObject("ADODB.Recordset")

    For x=0 To UBound(arrRecordsets)
        Set objCurrentRS = arrRecordsets(x)

        For Each objField In objCurrentRS.Fields
            blnExists = False
            For y=0 To objMergedRecordSet.Fields.Count-1
                If LCase(objMergedRecordSet.Fields(y).Name) = Lcase(objField.Name) Then
                    blnExists = True : Exit For
                End If
            Next
            If Not(blnExists) Then
                objMergedRecordSet.Fields.Append objField.Name, objField.Type, objField.DefinedSize
                'objMergedRecordSet.Fields(objMergedRecordset.Fields.Count-1).Attributes = 32 'adFldIsNullable
            End If
        Next
    Next

    objMergedRecordSet.Open

    For x=0 To UBound(arrRecordsets)
        Set objCurrentRS = arrRecordsets(x)

        Do Until objCurrentRS.EOF
            objMergedRecordSet.AddNew
            For Each objField In objCurrentRS.Fields
                If Not(IsNull(objField.Value)) Then
                    'Response.Write(objField.Name & "<br>")
                    'Response.Write(objField.Type & "<br>")
                    objMergedRecordSet.Fields(objField.Name).Value = objField.Value 'Here is where it throws the Error.
                End If
            Next
            objCurrentRS.MoveNext
        Loop
    Next

    objMergedRecordSet.MoveFirst
    Set MergeRecordSets = objMergedRecordSet
End Function

另外,请确保您没有试图将NULL放入不接受NULL值的列中。类型不匹配也可能导致此错误,因此请确保传递的是数值。
-Freddo

还请确保您没有试图将NULL放入不接受NULL值的列中。类型不匹配也可能导致此错误,因此请确保传递的是数值。
-Freddo

您提到您有
numeric
列,但在
objMergedRecordSet
中创建新字段时,您从未设置
Precision
NumericScale
属性。您需要为
adNumeric
adDecimal
字段设置这些属性

objMergedRecordSet.Fields.Append objField.Name, objField.Type, objField.DefinedSize
With objMergedRecordSet.Fields(objField.Name)
    .Precision = objField.Precision
    .NumericScale = objField.NumericScale
End With

您提到您有
numeric
列,但在
objMergedRecordSet
中创建新字段时,您从未设置
Precision
NumericScale
属性。您需要为
adNumeric
adDecimal
字段设置这些属性

objMergedRecordSet.Fields.Append objField.Name, objField.Type, objField.DefinedSize
With objMergedRecordSet.Fields(objField.Name)
    .Precision = objField.Precision
    .NumericScale = objField.NumericScale
End With

是的,这就是我们在八月份添加的修复。我再也没有回来更新这个答案。对于您的努力,我将给您答案复选标记。是的,这是我们在八月份添加的修复。我再也没有回来更新这个答案。为了你的努力,我将给你答案打勾。