嗨,我有一个从数据库中提取信息的 excel VB 程序。我的相关函数代码如下。这段代码工作了多年,现在我收到一个错误:“将数据类型 nvarchar 转换为 bigint 时出错”为什么会突然发生这种情况,解决方法是什么?
Public Function GetGiftCardsRedeem(iColumn As Integer, sFrom As String, sTo As String)
Dim rsResults As New ADODB.Recordset
Dim sSQL As String
Dim iRecordCount As Integer
' Assign the Connection object.
rsResults.ActiveConnection = gcnnDB
' Extract the required records.
sSQL = "Select Sum(dTotalAmount) as TotalAmount from GiftCardTransactions where dtCreated between '" & sFrom & " 00:00:00' and '" & sTo & " 23:59:59'"
sSQL = sSQL & " and CONVERT(BigINT, sCCNumber) Between 800110110000 and 800110159999" '800110110000
sSQL = sSQL & " and not sCCNumber is null and sCCNumber <> ''"
rsResults.Open sSQL, gcnnDB, adOpenStatic, adLockReadOnly, adCmdText
If Not rsResults.EOF Then
'Let's Cycle through the records..
'We need to move last and then move back first to get a correct recordCount.
DoEvents: DoEvents
Sheet1.Cells(MTD_FREEGIFTCARDS_QTY_ROW, iColumn) = rsResults.Fields("TotalAmount").Value
End If
rsResults.Close
End Function