我先用ADODB连接SQL数据库,但后面不知怎样写了,代码如下:
public mycon as new adodb.connection
public myres as new adodb.recordset
public function opencon ()
if mycon.state = 1 then
mycon.close
end if
mycon.open "连接SQL数据库的字符串"
end functionpublic function openres(byval strSql as string)
if myres.state = 1 then
myres.close
end if
with myres
.cursorlocation = aduseclient
.cursortype = adopendynamic
.open strSql,mycon,,,adcmdtext
end with
end function
以上代码是写在模块内的
后面的不知该怎么写了,望各位高手指教!!!!
public mycon as new adodb.connection
public myres as new adodb.recordset
public function opencon ()
if mycon.state = 1 then
mycon.close
end if
mycon.open "连接SQL数据库的字符串"
end functionpublic function openres(byval strSql as string)
if myres.state = 1 then
myres.close
end if
with myres
.cursorlocation = aduseclient
.cursortype = adopendynamic
.open strSql,mycon,,,adcmdtext
end with
end function
以上代码是写在模块内的
后面的不知该怎么写了,望各位高手指教!!!!
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream szConString = "Provider=sqloledb.1;Persist Security Info=False;User ID=sa;Initial Catalog=db;Data Source=(local);Password=soft
"
Set cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cn.Open szConString Set rs = New ADODB.Recordset
szSql = "Select * from photo_info " _
& " where photo_id='" & PhotoId & "'"
rs.Open szSql, cn, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("vehicle_photo").Value
szVehiclePhotoName = rs.Fields("vehicle_photo_name").Value
mstream.SaveToFile App.Path & "\"&szVehiclePhotoName,adSaveCreateOverWrite
Picture1.Picture = LoadPicture(App.Path & "\" & szVehiclePhotoName)
数据库中存放图像的字段是二进制类型(Access为OLE类型)。
比如,如果用“CommonDialog”控件来选择你硬盘上的图像文件;
用“Picture”控件来显示图像,那么下面的代码供参考:
(已连接数据库,打开了相应的记录集rs)
Dim StmPic As ADODB.Stream
Dim StrPicTemp As String
......
'保存你所选择的图像
Set StmPic = New ADODB.Stream
StmPic.Type = adTypeBinary '指定流是二进制类型
StmPic.Open '将数据获取到Stream对象中
StmPic.LoadFromFile (CommonDialog1.FileName) '将选择的图像加载到打开的StmPic中
rs.AddNew
rs.Fields(1).Value = StmPic.Read '从StmPic对象中读取数据
rs.Update
StmPic.Close
......
'读取显示数据库中的图像
Set StmPic = New ADODB.Stream
StrPicTemp = "c:\temp.tmp" '临时文件,用来保存读出的图片
With StmPic
.Type = adTypeBinary
.Open
.Write rs.Fields(1) '写入数据库中的数据至Stream中
.SaveToFile StrPicTemp, adSaveCreateOverWrite '将Stream中数据写入临时文件中
.Close
End With
Picture1.Picture = LoadPicture(StrPicTemp) '用Picture控件显示图像
......
我的幽香:[email protected]
主题写要图片ado