|
2#
楼主 |
发表于 2011-12-10 10:04:27
|
只看该作者
本帖最后由 t小宝 于 2011-12-10 11:48 编辑
鱼儿游游 发表于 2011-12-9 23:33
binary是定长的数组,应该用text,image等好些。
AppendChunk 好象不支持binary类型。
字段类型没有错,问题已经找到,是ReDim ByteData(FileLength) 多声明了一个字节,改为ReDim ByteData(FileLength-1)
就可以了。
正确的代码如下:- Public Function AppendFile()
- Dim cmdByRoyalty As ADODB.Command
- Dim prmByRoyalty As ADODB.Parameter
- Dim FileLength As Long
- Dim ByteData() As Byte
- Open "C:\test.rar" For Binary Access Read Lock Write As #1
- FileLength = LOF(1)
- ReDim ByteData(FileLength-1)
- Get #1, , ByteData()
- Close #1
- Set cmdByRoyalty = New ADODB.Command
- With cmdByRoyalty
- .CommandText = "PARAMETERS oleA LongBinary;INSERT INTO 表1 ( oo ) VALUES([oleA]);"
- .CommandType = adCmdText
- Set prmByRoyalty = .CreateParameter("oleA", adLongVarBinary, adParamInput, FileLength)
- .Parameters.Append prmByRoyalty
- prmByRoyalty.AppendChunk ByteData()
- Set .ActiveConnection = CurrentProject.Connection
- .Execute
- End With
-
- End Function
复制代码 |
|