ASP Classic将byte [] Request.BinaryRead放入数据库

时间:2013-02-03 17:07:43

标签: asp-classic vbscript

首先我要说的是我对此相当陌生,如果很明显我一直试图找到答案,我会很抱歉!

我正在尝试将一个byte []插入到我的数据库中的varbinary中,但是我正在打砖墙,所以我希望有人可以提供帮助。到目前为止,我有:

Dim biData, matchId
Dim sConnString, connection, recordset, sql, count

biData = Request.BinaryRead(Request.TotalBytes)
matchId = Request.ServerVariables("QUERY_STRING")

sql = "SELECT * FROM MatchData WHERE matchId= '" & matchId & "'"

'define the connection string, specify database
'driver and the location of database
sConnString="Driver={SQL Server};<CONNECTIONSTRING>"

Set connection = Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.Recordset") 

'Open the connection to the database
connection.Open(sConnString)

'Open the recordset object executing the SQL 
recordset.Open sql, connection,3,3

count=recordset.recordcount

If count > 0 Then
    response.Write("Found  ")
    recordset.Update "MatchId", matchId

    'MY PROBLEM IS HERE
    'recordset.Update "MatchData", biData
    'recordset.Fields("MatchData").AppendChunk biData
Else
    response.Write("Not Found  ")
    recordset.AddNew "MatchId", matchId

    'MY PROBLEM IS ALSO HERE
    'recordset.Update "MatchData", biData       
    'recordset.Fields("MatchData").AppendChunk(biData)
End If

recordset.Close
Set recordset=Nothing

'Done. Close the connection object
connection.Close
Set connection = Nothing

如果我只是返回biData,那么我会看到我上传的确切字节[]所以我猜它在那里,即     response.BinaryWrite biData

提前感谢您的回答

1 个答案:

答案 0 :(得分:0)

您需要在循环中追加二进制(块):

检查此页面: http://msdn.microsoft.com/en-us/library/windows/desktop/ms678200(v=vs.85).aspx

特别是这部分代码如何做到这一点:

Cnxn.Execute "INSERT publishers(pub_id, pub_name) VALUES('" & _
               strPubID & "','Your Test Publisher')"

' Add a new record, copying the logo in chunks
rstPubInfo.AddNew
rstPubInfo!pub_id = strPubID
rstPubInfo!pr_info = strPRInfo

lngOffset = 0 ' Reset offset
Do While lngOffset < lngLogoSize
    varChunk = LeftB(RightB(varLogo, lngLogoSize - lngOffset), _
        conChunkSize)
    rstPubInfo!logo.AppendChunk varChunk
    lngOffset = lngOffset + conChunkSize
Loop
rstPubInfo.Update