SQL中的查询结果怎么赋值给VB变量?
出了一个问题就是我用相对路径,Image1.Picture=LoadPicture(App.Path&"\1.jpg"),我把照片的名字全部起名叫做学号,但是关于SQL2...
出了一个问题就是我用相对路径,Image1.Picture = LoadPicture(App.Path & "\1.jpg"),我把照片的名字全部起名叫做学号,但是关于SQL2000中怎么样才能把学号赋值给VB中的一个变量?假如我的变量叫做A,然后这样Image1.Picture = LoadPicture(App.Path & "\A.jpg")是不是可以显示了?我在线等着大侠回答,还会加分啊!!!!
展开
2013-07-21
展开全部
Private conn As New ADODB.Connection
Private rs As New ADODB.Recordset
Private Sub Command1_Click()
Dim Sqlstr As String
Dim A As String
Sqlstr = "select * from Students Where S_name='" & text1.Text & "'"
Set rs = conn.Execute(Sqlstr)
If rs.EOF And rs.BOF Then
MsgBox "数据库中不存在该名字", , " 提示:"
Else
A = rs("S_id") '把查到的学号赋给变量 A
Image1.Picture = LoadPicture(App.Path & "\" & A & ".jpg") '显示该学生学号对于的照片
rs.Close
End If
End Sub
Private Sub Form_Load()
'ACCESS数据库连接方式
Dim DataPath As String
DataPath = App.Path & "\data.mdb" '数据库路径
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataPath & ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"
' ---------------------------
'sql server连接方式
' Dim ServerIP As String, UserName As String, Password As String, DataName As String
' ServerIP = "127.0.0.1" 'IP
' UserName = "linhaibo" '用户名
' Password = "pass" '密码
' DataName = "linhaibo" '数据库名
' conn.ConnectionString = "Driver={SQL Server}; Database=" & UserName & "; UID=" & UserName & "; PWD=" & Password & "; Server=" & ServerIP
' conn.Open
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
conn.Close
Set conn = Nothing
End Sub
Private rs As New ADODB.Recordset
Private Sub Command1_Click()
Dim Sqlstr As String
Dim A As String
Sqlstr = "select * from Students Where S_name='" & text1.Text & "'"
Set rs = conn.Execute(Sqlstr)
If rs.EOF And rs.BOF Then
MsgBox "数据库中不存在该名字", , " 提示:"
Else
A = rs("S_id") '把查到的学号赋给变量 A
Image1.Picture = LoadPicture(App.Path & "\" & A & ".jpg") '显示该学生学号对于的照片
rs.Close
End If
End Sub
Private Sub Form_Load()
'ACCESS数据库连接方式
Dim DataPath As String
DataPath = App.Path & "\data.mdb" '数据库路径
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataPath & ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"
' ---------------------------
'sql server连接方式
' Dim ServerIP As String, UserName As String, Password As String, DataName As String
' ServerIP = "127.0.0.1" 'IP
' UserName = "linhaibo" '用户名
' Password = "pass" '密码
' DataName = "linhaibo" '数据库名
' conn.ConnectionString = "Driver={SQL Server}; Database=" & UserName & "; UID=" & UserName & "; PWD=" & Password & "; Server=" & ServerIP
' conn.Open
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
conn.Close
Set conn = Nothing
End Sub
2013-07-21
展开全部
首先假设你从数据库中取出来的数据存储在记录集Rd中,并且照片名字在数据库表中的字段为Picname,则do while not Rd.eofA=Rd("Picname") '即可将照片的名字取出Image1.Picture = LoadPicture(App.Path & "\" & A & ".jpg") '这样就把这幅图片加载到Image1中了Rd.movenext '记录集向下移动一条,即再取下一个图片名字loop
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
A=RS(图片字段名) '如:0001。jpg 0002.jpgImage1.Picture = LoadPicture(App.Path & "\" & A )
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
Image1.Picture = LoadPicture(App.Path & "\" & A & ".jpg")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询