二进制吧 关注:3,247贴子:6,869
  • 0回复贴,共1

VB二进制保存图片access,数据类型一修改就报错

只看楼主收藏回复

VB以二进制流保存图片到access,数据库里的主键必须是自动编码,不是自动编码就报错,提示:
调试显示在Rs.Update
求高手帮解决下,非常感谢!!
代码如下:
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 = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\riyao.MDB"
Adodc1.RecordSource = "stock"
Adodc1.Refresh
End Sub
Private Sub Command3_Click() '保存图片到数据库
If mystr <> "" Then
Set Cn = New ADODB.Connection
Cn.ConnectionString = ";DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\riyao.MDB"
Cn.Open
Set Rs = New ADODB.Recordset
Rs.Open "select * from stock", Cn, adOpenStatic, 3
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 Command1_Click()
CommonDialog1.Filter = "bmp|*.jpg;*.bmp;*.gif"
CommonDialog1.FilterIndex = 2
' 显示"打开"对话框
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
mystr = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
End
End Sub


IP属地:江苏1楼2012-09-25 00:04回复