用我所有的分跪求!!!在客户端把照片存进数据库,在客户端从数据库中取出照片的代码!

shininggirl 2004-09-29 05:43:48
据说是要用sock通信,可是小女子从来没有用过VB(写过C#),明天要回家,车票都买好啦,无奈老大说明天不交工就不能回家,一点头绪都没有,哪位高人以前做过,可以把源码给我一份吗?不胜感激~~~怎么把所有的分都给出去啊,我给320分,系统提示错误啊!急急急!
...全文
165 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shininggirl 2004-10-08
怎么把所有的分给出去啊?
回复
shininggirl 2004-10-08
谢谢,放假都上不了网,今天才上来,感动啊!
回复
cqm2099 2004-10-03
UP
回复
lxcc 2004-09-29
上面是c#的
这是VB的
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;258038&Product=vbb
回复
lxcc 2004-09-29
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
回复
guxizhw 2004-09-29
不用跪求了,早点回家吧
回复
guxizhw 2004-09-29
Private Sub UPLoadAcc(ByVal strFileList As String, ByVal strPath As String)
''上传任何类型数据至image字段
Dim arrFile() As String

Dim i As Integer

Dim stm As New ADODB.Stream

Dim rs As New ADODB.Recordset

Dim cnAcc As New ADODB.Connection

Dim intMax As Integer

' If Not CheckKey Then Exit Sub 这个不要

arrFile = Split(strFileList, Chr(0))''文件名 你自己选一个就好 比如"c:\11.bmp"

cnAcc.Open strFileCon''连接字符串,不会写的话 ……%¥#※×((

cnAcc.CursorLocation = adUseClient

''取得最大序号,我自己的表,同你的有些不同
strSQL = "SELECT TOP 1 ship_accident_accessory_SN AS SN FROM HY_ship_accident_accessory WHERE ship_code=" & AddstringBracket(ShipCode) _
& " AND ship_accident_SN=" & AddstringBracket(Me.txtship_accident_SN.Text) _
& " ORDER BY ship_accident_accessory_SN DESC "

rs.Open strSQL, cnAcc, adOpenForwardOnly, adLockReadOnly, adCmdText

If rs.EOF And rs.BOF Then

intMax = 1

Else

intMax = rs(0) + 1

End If

strSQL = "SELECT * FROM HY_ship_accident_accessory"''打开附件表

If rs.state = adStateOpen Then rs.Close

rs.Open strSQL, cnAcc, adOpenStatic, adLockBatchOptimistic

With stm''打开流

.Type = adTypeBinary

.Open

End With

Screen.MousePointer = 11

On Error GoTo cancle

cnAcc.BeginTrans

For i = LBound(arrFile) To UBound(arrFile)''根据所有的文件名

rs.AddNew

rs("ship_code") = ShipCode

rs("ship_accident_SN") = Me.txtship_accident_SN.Text

rs("ship_accident_accessory_SN") = intMax

intMax = intMax + 1

rs("ship_accident_accessory_name") = arrFile(i)

stm.LoadFromFile strPath & arrFile(i)''load文件

rs("ship_accident_accessory_data") = stm.Read''存入文件

rs.Update

DoEvents

Next

rs.UpdateBatch

cnAcc.CommitTrans

Screen.MousePointer = 0

stm.Close

Set stm = Nothing

Set rs = Nothing

cnAcc.Close

Set cnAcc = Nothing

Exit Sub

cancle:

cnAcc.RollbackTrans

Set stm = Nothing

Set rs = Nothing

cnAcc.Close

Set cnAcc = Nothing

Screen.MousePointer = 0

MsgBox Err.Description

End Sub

Private Sub DownLoadAcc(ByVal strSNList As String, ByVal strDesDir As String)

Dim arr() As String

Dim i As Integer

Dim stm As New ADODB.Stream

Dim rs As New ADODB.Recordset

Dim cnAcc As New ADODB.Connection

cnAcc.Open strFileCon

rs.Open strSQL, cnAcc, adOpenStatic, adLockReadOnly

With stm

.Type = adTypeBinary

.Open

End With

Screen.MousePointer = 11

On Error GoTo cancle

While Not rs.EOF

stm.Write rs("AccFile")''用流读数据库

stm.SaveToFile strDesDir & "\" & rs("Fname"), adSaveCreateOverWrite''save到硬盘

rs.MoveNext''下一个

DoEvents

Wend

Screen.MousePointer = 0

stm.Close

Set stm = Nothing

Set rs = Nothing

cnAcc.Close

Set cnAcc = Nothing

Exit Sub

cancle:

Set stm = Nothing

Set rs = Nothing

cnAcc.Close

Set cnAcc = Nothing

Screen.MousePointer = 0

MsgBox Err.Description

End Sub
回复
vbman2003 2004-09-29
使用Stream对象,可以实现对数据库的图像存取。
数据库中存放图像的字段是二进制类型(Access为OLE类型)。
比如,如果用“CommonDialog”控件来选择你硬盘上的图像文件;
用“Picture”控件来显示图像,那么下面的代码供参考:
(运行VB,选择“工程\引用”命令,引用“Microsoft AetiveX Date 2.5 Library”。已连接数据库,打开了相应的记录集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控件显示图像
  ......

回复
shininggirl 2004-09-29
up!
回复
shininggirl 2004-09-29
不要掉下来!
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告