跪求:如何把图片信息存到Access数据库中,再通过数据库把图片调到VB里。
怎样把数据库和VB连接起来?然后存图片,在以后用图片的时候再用数据库调到VB中进行一些操作,如放大、缩小等操作。最好附有程序,我是新手,望大家帮助!...
怎样把数据库和VB连接起来?然后存图片,在以后用图片的时候再用数据库调到VB中进行一些操作,如放大、缩小等操作。最好附有程序,我是新手,望大家帮助!
展开
展开全部
方法1:
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\data.mdb"
Data1.RecordSource = "data"
End Sub
Private Sub Form_Activate()
Image2.Picture = LoadPicture(Text1(2).Text)
End Sub
Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Enabled = False
command3.Enabled = True
Command2.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command2_Click()
Data1.Recordset.Update
Data1.Enabled = True
command3.Enabled = False
Command2.Enabled = False
Command1.Enabled = True
End Sub
Private Sub Command3_Click()
CmD1.DialogTitle = "Ñ¡ÔñͼƬ"
CmD1.Filter = "bmp|*.bmp;*.ico"
CmD1.ShowOpen
If Len(CmD1.FileName) Then
Text1(2).Text = CmD1.FileName
Image1.Picture = LoadPicture(Text1(2).Text)
Image2.Picture = LoadPicture(Text1(2).Text)
End If
End Sub
Private Sub Data1_Reposition()
Image2.Picture = LoadPicture(Text1(2).Text)
End Sub
Private Sub Command4_Click()
End
End Sub
方法2:
Option Explicit
Dim Cn As ADODb.Connection
Dim Rs As ADODb.Recordset
Dim mst As ADODb.Stream
Dim mystr As String
Private Sub Form_Load()
Adodc1.ConnectionString = "uid=admin;pwd=111;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.MDB"
Adodc1.RecordSource = "data"
Adodc1.Refresh
End Sub
Private Sub Command1_Click()
If mystr <> "" Then
Set Cn = New ADODb.Connection
Cn.ConnectionString = ";DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.MDB"
Cn.Open
Set Rs = New ADODb.Recordset
Rs.Open "select * from data", Cn, adOpenStatic, adLockOptimistic
Set mst = New ADODb.Stream
mst.Type = adTypeBinary
mst.Open
mst.LoadFromFile mystr
Rs.AddNew
Rs.Fields("图片").Value = mst.Read
Rs.Update
Rs.Close
Cn.Close
Adodc1.Refresh
Else
MsgBox ("请选择图片¡")
End If
End Sub
Private Sub Command3_Click()
CommonDialog1.Filter = "bmp|*.jpg;*.bmp;*.gif"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
mystr = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\data.mdb"
Data1.RecordSource = "data"
End Sub
Private Sub Form_Activate()
Image2.Picture = LoadPicture(Text1(2).Text)
End Sub
Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Enabled = False
command3.Enabled = True
Command2.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command2_Click()
Data1.Recordset.Update
Data1.Enabled = True
command3.Enabled = False
Command2.Enabled = False
Command1.Enabled = True
End Sub
Private Sub Command3_Click()
CmD1.DialogTitle = "Ñ¡ÔñͼƬ"
CmD1.Filter = "bmp|*.bmp;*.ico"
CmD1.ShowOpen
If Len(CmD1.FileName) Then
Text1(2).Text = CmD1.FileName
Image1.Picture = LoadPicture(Text1(2).Text)
Image2.Picture = LoadPicture(Text1(2).Text)
End If
End Sub
Private Sub Data1_Reposition()
Image2.Picture = LoadPicture(Text1(2).Text)
End Sub
Private Sub Command4_Click()
End
End Sub
方法2:
Option Explicit
Dim Cn As ADODb.Connection
Dim Rs As ADODb.Recordset
Dim mst As ADODb.Stream
Dim mystr As String
Private Sub Form_Load()
Adodc1.ConnectionString = "uid=admin;pwd=111;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.MDB"
Adodc1.RecordSource = "data"
Adodc1.Refresh
End Sub
Private Sub Command1_Click()
If mystr <> "" Then
Set Cn = New ADODb.Connection
Cn.ConnectionString = ";DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.MDB"
Cn.Open
Set Rs = New ADODb.Recordset
Rs.Open "select * from data", Cn, adOpenStatic, adLockOptimistic
Set mst = New ADODb.Stream
mst.Type = adTypeBinary
mst.Open
mst.LoadFromFile mystr
Rs.AddNew
Rs.Fields("图片").Value = mst.Read
Rs.Update
Rs.Close
Cn.Close
Adodc1.Refresh
Else
MsgBox ("请选择图片¡")
End If
End Sub
Private Sub Command3_Click()
CommonDialog1.Filter = "bmp|*.jpg;*.bmp;*.gif"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
mystr = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
End
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询