日期:2014-05-17  浏览次数:21286 次

都是数字,但就是不匹配
子程序如下
sub   UpdateTotalSizeStatus(method,filesize,userID)
'method:加还是减
'Filesize:文件大小
'userID:用户ID
UpdateTotalSizesql   =   "Update   [Members]   SET   [UploadSizeTotal]   =   [UploadSizeTotal] "&method&filesize& "   WHERE   [userID]= "&userID
set   UpdateTotalSizers   =   Server.CreateObject( "adodb.recordset ")
UpdateTotalSizers.open   UpdateTotalSizesql,conn,1,3

set   UpdateTotalSizers=nothing
end   sub

用来更新用户上传数量,UploadSizeTotal的字段类型是:numeric(18,   0)

有时候可以更新,有时候就提示不匹配。请高人指教。

------解决方案--------------------
换用字符型比较安全

如果你是数字型的可以考虑这样
sub UpdateTotalSizeStatus(method,filesize,userID)
'method:加还是减
'Filesize:文件大小
'userID:用户ID
temp=cstr(method)+cstr(filesize)
temp=ccur(temp)
temp_length=temp\10
UpdateTotalSizesql = "Update [Members] SET [UploadSizeTotal] = [UploadSizeTotal]* "&temp_length& "+ "&temp& " WHERE [userID]= "&userID
set UpdateTotalSizers = Server.CreateObject( "adodb.recordset ")
UpdateTotalSizers.open UpdateTotalSizesql,conn,1,3

set UpdateTotalSizers=nothing
end sub


------解决方案--------------------
sub UpdateTotalSizeStatus(method,filesize,userID)

Dim TotalSizers
If method = "+ " Then
TotalSizers = FileSize
Else
TotalSizers = -FileSize '取负数
End If

UpdateTotalSizesql = "Update [Members] SET [UploadSizeTotal] = [UploadSizeTotal] + "& TotalSizers & " WHERE [userID]= "&userID
set UpdateTotalSizers = Server.CreateObject( "adodb.recordset ")
UpdateTotalSizers.open UpdateTotalSizesql,conn,1,3
set UpdateTotalSizers=nothing
end sub
------解决方案--------------------
我个人认为,要是进行比较还是换成字符型比较好一些。数值型常会出现一些问题
sub UpdateTotalSizeStatus(method,filesize,userID)
'method:加还是减
'Filesize:文件大小
'userID:用户ID
temp=cstr(method)+cstr(filesize)
temp=ccur(temp)
temp_length=temp\10
UpdateTotalSizesql = "Update [Members] SET [UploadSizeTotal] = [UploadSizeTotal]* "&temp_length& "+ "&temp& " WHERE [userID]= "&userID
set UpdateTotalSizers = Server.CreateObject( "adodb.recordset ")
UpdateTotalSizers.open UpdateTotalSizesql,conn,1,3

set UpdateTotalSizers=nothing
end sub