| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1029 人关注过本帖
标题:请问这些代码是什么意思
只看楼主 加入收藏
kevinhong
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2005-7-15
收藏
 问题点数:0 回复次数:3 
请问这些代码是什么意思

这些程序是一个图像显示的程序,

Dim con As New ADODB.Connection

Private Sub Combo1_Click() ' 点击图像下接列表
Dim rs As ADODB.Recordset
Dim b() As Byte
'从数据为中取数据
Set rs = con.Execute("select imageValue from images where imageName='" & Combo1.Text & "'")
If (Not rs.EOF) Then

'将数据库中的数据写入到文件中
'改变可变数组的大小
ReDim b(rs.Fields(0).ActualSize)
b = rs.Fields(0).Value
'如果没有temp目录,产生一个新的目录
If (Dir(App.Path & "/temp", vbDirectory) = Empty) Then
MkDir (App.Path & "/temp")
End If
Dim filename As String
filename = App.Path & "/temp" & "/" & Combo1.Texts
Dim ch As Long
ch = FreeFile
Open filename For Binary As #ch
Put #ch, , b
Close #ch
Picture1.Picture = LoadPicture(filename)
rs.Close
Else
MsgBox "没有对应的数据"
End If
End Sub

Private Sub Command1_Click() '打開
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.filename
End Sub

Private Sub Command2_Click() '写入数据库
Dim b() As Byte
ReDim b(FileLen(Text1.Text))
Dim ch As Long
ch = FreeFile
Open Text1.Text For Binary As #ch
Get #ch, , b
Close #ch
Dim sql As String
Dim rs As ADODB.Recordset
sql = "select count(*) from images where imageName='" & CommonDialog1.FileTitle & "'"
Set rs = con.Execute(sql)
Dim rsw As New ADODB.Recordset
If (rs.Fields(0).Value >= 1) Then
sql = "select * from images where imageName='" & CommonDialog1.FileTitle & "'"
rsw.Open sql, con, adOpenDynamic, adLockPessimistic
Else
rsw.Open "images", con, adOpenDynamic, adLockPessimistic
rsw.AddNew
End If
rsw.Fields(0).Value = CommonDialog1.FileTitle
rsw.Fields(1).Value = b

rsw.Update
rsw.Close
Call getData
MsgBox "写入成功!!!!"
End Sub

Private Sub Form_Load()
con.ConnectionString = "driver={sql server};server=localhost;database=w03;pwd=;uid=sa"
con.Open
Call getData
End Sub

Private Sub getData()
Dim sql As String
sql = "select imageName from images"
Dim rs As ADODB.Recordset
Set rs = con.Execute(sql)
Combo1.Clear
While (Not rs.EOF)
Combo1.AddItem rs.Fields(0).Value
rs.MoveNext
Wend
rs.Close
End Sub

请问红色代码部份是什么意思呢?谢谢!

搜索更多相关主题的帖子: 代码 
2005-11-24 12:17
kevinhong
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2005-7-15
收藏
得分:0 
这是上面的设计页面
图片附件: 游客没有浏览图片的权限,请 登录注册

Dim con As New ADODB.Connection

Private Sub Combo1_Click() ' 点击图像下接列表
Dim rs As ADODB.Recordset
Dim b() As Byte
'从数据为中取数据
Set rs = con.Execute("select imageValue from images where imageName='" & Combo1.Text & "'")
If (Not rs.EOF) Then

'将数据库中的数据写入到文件中
'改变可变数组的大小
ReDim b(rs.Fields(0).ActualSize)
b = rs.Fields(0).Value
'如果没有temp目录,产生一个新的目录
If (Dir(App.Path & "/temp", vbDirectory) = Empty) Then
MkDir (App.Path & "/temp")
End If
Dim filename As String
filename = App.Path & "/temp" & "/" & Combo1.Texts
Dim ch As Long
ch = FreeFile
Open filename For Binary As #ch
Put #ch, , b
Close #ch
Picture1.Picture = LoadPicture(filename)
rs.Close
Else
MsgBox "没有对应的数据"
End If
End Sub

Private Sub Command1_Click() '打開
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.filename
End Sub

Private Sub Command2_Click() '写入数据库
Dim b() As Byte
ReDim b(FileLen(Text1.Text))
Dim ch As Long
ch = FreeFile
Open Text1.Text For Binary As #ch
Get #ch, , b
Close #ch
Dim sql As String
Dim rs As ADODB.Recordset
sql = "select count(*) from images where imageName='" & CommonDialog1.FileTitle & "'"
Set rs = con.Execute(sql)
Dim rsw As New ADODB.Recordset
If (rs.Fields(0).Value >= 1) Then
sql = "select * from images where imageName='" & CommonDialog1.FileTitle & "'"
rsw.Open sql, con, adOpenDynamic, adLockPessimistic
Else
rsw.Open "images", con, adOpenDynamic, adLockPessimistic
rsw.AddNew
End If
rsw.Fields(0).Value = CommonDialog1.FileTitle
rsw.Fields(1).Value = b
rsw.Update
rsw.Close
Call getData
MsgBox "写入成功!!!!"
End Sub

Private Sub Form_Load()
con.ConnectionString = "driver={sql server};server=localhost;database=w03;pwd=;uid=sa"
con.Open
Call getData
End Sub

Private Sub getData()
Dim sql As String
sql = "select imageName from images"
Dim rs As ADODB.Recordset
Set rs = con.Execute(sql)
Combo1.Clear
While (Not rs.EOF)
Combo1.AddItem rs.Fields(0).Value
rs.MoveNext
Wend
rs.Close
End Sub

请问红色代码部份是什么意思呢?谢谢!


饮水思源.懂得感恩!!!
2005-11-24 12:18
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
sql = "select count(*) from images where imageName='" & CommonDialog1.FileTitle & "'"
这句话的意思应该是返回images表中,图片名称CommonDialog1.FileTitle不等于空的数据的数量。

If (rs.Fields(0).Value >= 1) Then这个意思是返回>=1就表示CommonDialog1.FileTitle这个图片的名称在数据库中应该是存在的。

sql = "select * from images where imageName='" & CommonDialog1.FileTitle & "'"
rsw.Open sql, con, adOpenDynamic, adLockPessimistic
这两句的目的应该是如果该图片在数据库中存在,就对数据库进行更新

rsw.Open "images", con, adOpenDynamic, adLockPessimistic
rsw.AddNew
这两句在Else后面,应该表示不存在就要进行向数据库添加数据的操作。
2005-11-24 15:30
论坛元老
Rank: 1
等 级:新手上路
帖 子:812
专家分:0
注 册:2008-3-31
收藏
得分:0 
帮不上忙,I'SORRY.....
2008-04-02 14:58
快速回复:请问这些代码是什么意思
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018170 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved