1.写入-- 1.1 SQL Server创建存储过程 create proc [存储过程名] (@参数名 image) as begin insert into [数据库名].[架构名].[表名]([image字段]) values(@参数名) end -- 1.2 VB写入image类型字段 Dim x as ADODB.Stream Set x = New ADODB.Stream x.Type = adTypeBinary x.Open x.LoadFromFile ("[文件路径]\[文件名]")
Dim adoCn as ADODB.Connection Set adoCn = New ADODB.Connection adoCn.CursorLocation = adUseClient adoCn.Open "[数据库连接串]" Dim adoCmd as ADODB.Command Set adoCmd = New ADODB.Command adoCmd.ActiveConnection = adoCn adoCmd.CommandType = adCmdStoredProc adoCmd.CommandText = "[存储过程名]" adoCmd.Parameters.Append adoCmd.CreateParameter("[参数名]", adBinary, adParamInput, x.Size, x.Read) adoCmd.Execute 2.读取-- 2.1 SQL Server创建存储过程 create proc [存储过程名] as begin select [image字段名] from [数据库名].[架构名].[表名] end -- 2.2 VB读取image类型字段 Dim adoCn as ADODB.Connection Set adoCn = New ADODB.Connection adoCn.CursorLocation = adUseClient adoCn.Open "[数据库连接串]" Dim adoRs as ADODB.Recordset Set adoRs = New ADODB.Recordset adoRs.Open "exec [存储过程名]", adoCn, adOpenKeyset, adLockReadOnly If adoRs.RecordCount > 0 Then Set x = New ADODB.Stream x.Type = adTypeBinary x.mode = adModeReadWrite x.Open x.Write adoRs.Fields(0) x.SaveToFile [文件路径]\[文件名], adSaveCreateOverWrite End If
create proc [存储过程名]
(@参数名 image)
as
begin
insert into [数据库名].[架构名].[表名]([image字段]) values(@参数名)
end
-- 1.2 VB写入image类型字段
Dim x as ADODB.Stream
Set x = New ADODB.Stream
x.Type = adTypeBinary
x.Open
x.LoadFromFile ("[文件路径]\[文件名]")
Dim adoCn as ADODB.Connection
Set adoCn = New ADODB.Connection
adoCn.CursorLocation = adUseClient
adoCn.Open "[数据库连接串]" Dim adoCmd as ADODB.Command
Set adoCmd = New ADODB.Command
adoCmd.ActiveConnection = adoCn
adoCmd.CommandType = adCmdStoredProc
adoCmd.CommandText = "[存储过程名]"
adoCmd.Parameters.Append adoCmd.CreateParameter("[参数名]", adBinary, adParamInput, x.Size, x.Read) adoCmd.Execute
2.读取-- 2.1 SQL Server创建存储过程
create proc [存储过程名]
as
begin
select [image字段名] from [数据库名].[架构名].[表名]
end
-- 2.2 VB读取image类型字段
Dim adoCn as ADODB.Connection
Set adoCn = New ADODB.Connection
adoCn.CursorLocation = adUseClient
adoCn.Open "[数据库连接串]" Dim adoRs as ADODB.Recordset
Set adoRs = New ADODB.Recordset
adoRs.Open "exec [存储过程名]", adoCn, adOpenKeyset, adLockReadOnly If adoRs.RecordCount > 0 Then
Set x = New ADODB.Stream
x.Type = adTypeBinary
x.mode = adModeReadWrite
x.Open
x.Write adoRs.Fields(0)
x.SaveToFile [文件路径]\[文件名], adSaveCreateOverWrite
End If