我老婆初学VB,我又是VC中的强鸟,VB中的菜鸟,所以还请各路高手帮帮忙:)
问题是:怎么把图片放到数据库,当然也要能取得回来
我只知道用BLOB,可是我对Image控件什么的一点都不熟,所以还是靠大家了,可以的话顺便解释一下Image(或者叫Picture,我忘了)控件的绑定到数据库是怎么一回事, 多谢了

解决方案 »

  1.   

    see在VB中存取数据库中的图片
    http://www.yesky.com/20010705/188008.shtmlAppendChunk and GetChunk Methods Example (VB)
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdaexamples_vb01_8.aspSave/Retrieve Image From SQL Server Database Using Ado 2.5 Stream Object
    http://www.freevbcode.com/ShowCode.Asp?ID=1802
      

  2.   

    存储图像数据的方法  1 建立具有image宇段的SQL Server数据库  当需要在SQL Server数据库中存储图像数据时,首先应建立包含image数据类型字段的数据库关系表。SQL Server数据库平台支持的数据类型中,image数据类型主要用于存储图像数据等大段的二进制数据。SQL Server 7.0之后的版本,image类型可存储2GB的数据。   2 使用Remote Data控件建立与数据库的连接  Remote Data控件是在Visual Basic应用程序中用来获取远程数据的控件。它在.远程数据对象(RDO)和数据绑定控件之间提供了接口,只要给它提供有关数据存储的位置、获取的数据和一些接口控制,就可以连接到数据库,实现对数据库的基本操作。   使用Remote Data控件建立与远程数据库的连接步骤如下:  1.在Visual Basic的窗体中加入一个Remote Data控件。 ,  2.在Remote Data控件DataSourceName属性的下拉列表中选择一个ODBC数据源。例如pubs。  3.在Remote Data控件的SQL属性中输入SQL查询语句。例如,Select * from pub_info。  2.3 绑定OLE和Remote Data控件实现图像数据的存储与编辑  OLE是允许应用程序相互之间交换和显示数据的一项技术,使用OLE,可以从支持OLE技术的任何应用程序中读取信息,也可以在任何支持OLE的程序中显示和编辑它。在Visual Basic中,可利用OLE容器控件与Remote Data控件的绑定,来实现显示、存储和编辑SQL Serve数据库中的image类型数据。  1.显示SQL Serve数据库image类型字段的图像数据  具体步骤如下:  (1)在加入了Remote Data控件的Visual Basic的窗体中,添加一个OLE容器控件。创建OLE容器控件时,会出现“插入对象’:对话框,此时点击“取消”按钮,不必为该容器指定对象。  (2)将OLE容器控件的DataSource属性设置为Remote Data控件的名字,实现控件的绑定。  (3)在OLE容器控件。DataField属性的下拉列表中选择要显示的字段名。例如,logo。  (4)运行应用程序。对于包含image数据类型的logo字段的数据将在OLE容器控件中显示一幅图像。  2.在SQL Sever数据库image类型字段中添加存储图像数据  具体步骤如下:  (1)将Remote Data控件的EOFAction属性设置为rdAddNew,实现数据库的数据添加功能。  (2)在Visual Baisic的窗体中添加一个CommandButton控件,并编写图像文件嵌入OLE容器控件的程序代码。例如:Private Sub Command_Click()OLEl.CreateEmbed“c:\图片.bmp”End Sub   (3)运行应用程序,点击Remote Data控件的记录指示按钮,移动到新的记录,然后点击CommandButton控件按钮,实现图像数据的添加入库操作。  3.编辑SQL Serve数据库image数据类型字段的图像数据  具体步骤如下:  (1)在Visual Basic的窗体中添加一个CommandButton控件,编写对OLE对象的编辑程序代码。例如:Private Sub Command2--_Click()OLEl.DoVerb VbOLEOpenEnd Sub    (2)运行应用程序,点击Remote Data控件的记录指示按钮,选择需要编辑的图像,然后点击CommandButton控件按钮,在分隔的应用程序窗口打开对象,进行图像的编辑操作。  4、图像文件自动入库方式的实现  在数据库的实际应用中,经常需要将图像文件批量存储,以提高数据入库操作的自动化程度。对于图像文件批量存储,在程序代码的编写中,可充分利用OLE容器控件与RemoteData控件的诸多属性和方法,加以实现。  具体步骤如下:  (1)将OLE和RemoteData控件的Visible属性设置成False,使OLE和RemoteData控件不可视。  (2)建立图像文件的批处理文件。  (3)编写以下基本代码,实现批处理功能。Private Sub Command3_Click()Dim FileName As StringOpen "c:\tesffile.txt"ForlnputAs#1'打开批处理文件。DoWhileNotEOF(1)'循环至文件尾。Input#l,FileName'读入图像文件名。MSRDCl.Resultset.AddNew‘结果集添加记录OLEl.CreateEmbedFileName‘嵌入图像文件MSRDCl.Resultset.UpdateLoopClose #1End Sub   (4)运行应用程序。点击CommandButton控件按钮,完成图像文件的自动入库。
      

  3.   

    你有信箱吗,我给你发个例程,:)
    我的信箱是[email protected]
      

  4.   

    用adodb;库结构 库明:照片库  (mdb)字段2个1、序号2、照片1、取照片    Dim rst As ADODB.Recordset
        Dim bit1() As Byte
        xx = "select 照片 from 照片库 where  序号=" & Val(Trim(txt(1).Text))
        Set rst = chaxun(xx, yy)
        If rst.RecordCount > 0 Then
                Image1.Picture = Nothing
                If rst("照片").ActualSize > 0 Then
                    Image1.Stretch = False
                    bit1 = rst.Fields("照片").GetChunk(rst("照片").ActualSize)
                    '然后将字节数组的内容拼装成文件即可
                    Open "c:\1.bmp" For Binary As #1
                  
                    Put 1, 1, bit1
                    Close 1
                    Image1.Picture = LoadPicture("c:\1.bmp")
                    Kill ("c:\1.bmp")
                   end if
        Else
        MsgBox "照片库无" & Trim(txt(2).Text) & "的照片", , "提示"
        Check1.Value = 0
        End If2、加照片Dim rst As ADODB.Recordset
      xx = "select 序号 from 照片库 where 序号=" & Val(Trim(txt(1).Text))
      Set rst = chaxun(xx, yy)
      If rst.RecordCount > 0 Then Check1.Value = 1: Exit Sub
      Dim bit() As Byte
      Dim varPath As String '图片的路径
      CommonDialog1.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"
      CommonDialog1.ShowOpen
      varPath = CommonDialog1.FileName
      If varPath = "" Then Exit Sub
      xx = "select * from 照片库"
      Set rst = chaxun(xx, yy)
        
        
                Open varPath For Binary As #1
                ReDim bit(LOF(1)) As Byte
                Get 1, 1, bit
                Close 1
             '    然后将字节数组的内容写入数据库即可
                rst.AddNew
                rst.Fields("照片").AppendChunk bit
                rst.Fields("序号") = Val(txt(1).Text)
                rst.Update
                Image1.Picture = LoadPicture(varPath)
    3、换照片Dim rst As ADODB.Recordset
      Dim bit() As Byte
      Dim varPath As String '图片的路径
       CommonDialog1.Filter = "Pictures (*.bmp;*.jpg)|*.bmp;*.jpg"
      CommonDialog1.ShowOpen
      varPath = CommonDialog1.FileName
      If varPath = "" Then Exit Sub
      
      xx = "select * from 照片库 where 序号=" & Val(Trim(txt(1).Text))
      Set rst = chaxun(xx, yy)
      
      
                Open varPath For Binary As #1
                ReDim bit(LOF(1)) As Byte
                Get 1, 1, bit
                Close 1
                rst.Fields("照片").AppendChunk bit
                rst.Update
                Image1.Picture = LoadPicture(varPath)
                Image1.Refresh4、删除照片 Dim rst As ADODB.Recordset
        xx = "delete from 照片库 where 序号=" & Val(Trim(txt(1).Text))
        Set rst = chaxun(xx, yy)
        MsgBox yy
        Image1.Picture = Nothing
    5、公用函数Public Function chaxun(ByVal sql As String, msgstring As String) As ADODB.Recordset
        On Error GoTo ExecuteSQL_Error
        
        Dim cN As ADODB.Connection
        Dim rst As ADODB.Recordset
        Dim a() As String
        Set cN = New ADODB.Connection
        
        
        Dim str As String
        str = App.Path
        If Right(str, 1) <> "\" Then
           str = str + "\"
        End If    cN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\_data.mdb;Persist Security Info=False;jet OLEDB:Database password=422127197509080072"
        cN.Open
        
        
        a = Split(sql)
        
        If InStr("insert,delete,updata", Trim(a(0))) Then
            cN.Execute sql
            Select Case Trim(a(0))
                Case "insert"
                    msgstring = "添加记录"
                Case "delete"
                    msgstring = "删除记录"
                Case "updata"
                    msgstring = "更新记录"
            End Select
            msgstring = msgstring & "已完成"
        Else
            
            Set rst = New ADODB.Recordset
            rst.CursorLocation = adUseClient
            rst.Open sql, cN, adOpenKeyset, adLockOptimistic
            
            Set chaxun = rst
            msgstring = "查询到" & rst.RecordCount & "条记录"
        End If
        
    ExecuteSQL_Exit:
        Set rst = Nothing
        Set cN = Nothing
        Exit Function
        
    ExecuteSQL_Error:
        msgstring = "查询错误: " & _
        err.Description
        Resume ExecuteSQL_Exit
    End Function
      

  5.   

    [email protected]       我也要!!!
      

  6.   

    http://www.yesky.com/20010705/188008.shtml  里的说明:
      《按“添加”按钮选择对应的数据源驱动程序Access的*.mdb或者SQL Server,依照添加向导 加添加数据源》
      看不懂
      

  7.   

    发个例程给我呀!
      邮箱:[email protected]
      

  8.   

    我有完整程序发给你!你的email是……