Option Explicit
Dim path As String
Dim Rst As New ADODB.Recordset
Private Sub Command1_Click()
Dim mstream As New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
Rst.MoveFirst
If CommonDialog1.FileName <> vbNullString Then
    mstream.LoadFromFile CommonDialog1.FileName
    Rst.Fields("szp").Value = mstream.Read()
    Rst.Update   '问题就是这里,说什么“缺少要更新或刷新的键列信息”
End Ifmstream.Close
Set mstream = NothingEnd SubPrivate Sub Command2_Click()
Call LoadPicture
End SubPrivate Sub Form_Load()On Error GoTo ErrorHandleRst.ActiveConnection = gCnn
Rst.CursorLocation = adUseClient
Rst.CursorType = adOpenDynamic
Rst.LockType = adLockOptimistic
Rst.Source = "select szp from s_info where sxh='001144029'"
Rst.Open
ErrorHandle:
If Err.Number <> 0 Then
MsgBox "数据库出错" & Chr(10) & "错误" & Err.Description, vbOKOnly + vbExclamation, "提示"
End If
End Sub
Private Sub Image1_Click()
Dim path As String
CommonDialog1.Filter = "*.*"
CommonDialog1.Action = 1
path = CommonDialog1.FileName
Image1.Picture = VB.LoadPicture(path)
End SubPrivate Sub LoadPicture()    '将数据中的zp字段值用数据流读出,保存在临时路径下!
Dim mstream As ADODB.Stream
Dim filepath As String
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
Rst.MoveFirst
If Trim(Rst.Fields("szp").Value) = "" Then                  
Set mstream = Nothing
          Exit Sub
End If
       filepath = App.path & "\tmpimage.bmp"                '临时路径为当前路径下的"\tmpimage.bmp"文件可以随便取文件名称
       mstream.Write Rst.Fields("szp").Value
       mstream.SaveToFile filepath, adSaveCreateOverWrite   '保存图像到临时路径,临时如果临时路径上有图像,则覆盖原图像
       mstream.Close
Set mstream = Nothing
Image1.Picture = VB.LoadPicture(filepath)    '从临时路径FilePath导出图像
End Sub'问题就是这里,说什么“缺少要更新或刷新的键列信息”,帮忙。。

解决方案 »

  1.   

    参考:http://www.china-askpro.com/msg41/qa82.shtmlhttp://www.china-askpro.com/msg19/qa54.shtml
      

  2.   

    救急,,,高手可以给写个程序解决吗???
    我以前看了很多方法都是什么ADDNEW的,我要的是更新,不是添加
      

  3.   

    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim mstream As ADODB.Stream

    Set rs = New ADODB.Recordset
    rs.Open "Select * from table", cn, adOpenKeyset, adLockOptimisticSet mstream = New ADODB.Stream
    mstream.Type = adTypeBinary
    mstream.Open
    mstream.LoadFromFile "<path to  file>"
    rs.Fields("szp").Value = mstream.Read
    rs.Updaters.Close
    cn.Close
      

  4.   

    To code8110(业余选手) 
    你的方法和我提供的程序有区别吗????好象一样的。
    我需要调试好的例子,,,,