'服务端将记录集转化为二进制发送
Public Function RecordsetToBimary(rs As Recordset) As Byte()
Dim stm As Stream
Set stm = New Stream
stm.Open
stm.Type = adTypeBinary
rs.Save stm, adPersistADTG
stm.Position = 0
RecordsetToBimary = stm.Read()
Set stm = Nothing
End Function
'客户端将二进制转化为记录集
Public Function BimaryToRecordset(vData() As Byte) As Recordset
Dim stm As Stream
Dim rs As Recordset
Set stm = New Stream
stm.Open
stm.Type = adTypeBinary
stm.Write vData
stm.Position = 0
Set rs = New Recordset
rs.Open stm
Set BimaryToRecordset = rs
Set rs = Nothing
Set stm = Nothing
End Function
小弟新手,最近试着编个网络数据库,但是不知道客户端查询后的记录集服务器该如何返回,网上找了不少,上面的代码也是从网上copy过来的,
试着在自己的程序中用了一下,但是运行到客户端中rs.open stm时系统报错:无法从指定的源创建记录集,源文件或流必须包含XML或ADTG格式的记录集数据。
有高手能指点一下该如何操作吗?先行谢过了
Public Function RecordsetToBimary(rs As Recordset) As Byte()
Dim stm As Stream
Set stm = New Stream
stm.Open
stm.Type = adTypeBinary
rs.Save stm, adPersistADTG
stm.Position = 0
RecordsetToBimary = stm.Read()
Set stm = Nothing
End Function
'客户端将二进制转化为记录集
Public Function BimaryToRecordset(vData() As Byte) As Recordset
Dim stm As Stream
Dim rs As Recordset
Set stm = New Stream
stm.Open
stm.Type = adTypeBinary
stm.Write vData
stm.Position = 0
Set rs = New Recordset
rs.Open stm
Set BimaryToRecordset = rs
Set rs = Nothing
Set stm = Nothing
End Function
小弟新手,最近试着编个网络数据库,但是不知道客户端查询后的记录集服务器该如何返回,网上找了不少,上面的代码也是从网上copy过来的,
试着在自己的程序中用了一下,但是运行到客户端中rs.open stm时系统报错:无法从指定的源创建记录集,源文件或流必须包含XML或ADTG格式的记录集数据。
有高手能指点一下该如何操作吗?先行谢过了
rs.Save "c:\test.rs"
'读取
rs.Open "c:\test.rs"
Dim b() As Byte
Dim oP As New PropertyBag
Call oP.WriteProperty("MyRs", ors)
b = oP.Contents'//读取
oP.Contents = b
Set ors = oP.ReadProperty("MyRs")
recordset.Open Source, ActiveConnection, CursorType, LockType, Options参数Source 可选,变体型,计算 Command 对象的变量名、SQL 语句、表名、存储过程调用或持久 Recordset 文件名。
使用可选的 Source 参数指定使用下列内容之一的数据源:Command 对象变量、SQL 语句、存储过程、表名或完整的文件路径名。如果 Source 是文件路径名,它可以是完整路径(“c:\dir\file.rst”)、相对路径(“..\file.rst”)或 URL(“http://files/file.rst”)。
那么,在代码中rs.open stm这种写法可以吗,感觉此时stm通过前面的操作应该成为一个有内容的流对象了,但为什么会报错呢?希望高手能多讲点原因方面的和调整方法,授人以渔,拜谢
你说的那个PropertyBag函数该怎么用啊
WriteProperty(Name As String, Value, [DefaultValue])
ReadProperty(Name As String, [DefaultValue])
Contents As Variant
Call oP.WriteProperty("MyRs", ors)
b = oP.Contents '//读取
oP.Contents = b
Set ors = oP.ReadProperty("MyRs")
你给的例子中myrs值是可以任一字符串吗?ors我看是记录集属性,这是函数定义好的属性呢,还是可以变的,函数的意思我基本看明白了,就是对参数不太明白,在网上找了下,都说得不太明白,英文不好只能找中文的,如你能再来,麻烦讲解下