有一张表tbl1,包含tex(text文本)、id(int)、dt(date)、pic(image)四个列。我用datagrid控件显示id(int)、dt(date)两列。用image控件加载pic(image).程序如下:
Dim adodc As ADODB.Connection
Dim ADORst As ADODB.Recordset
Private Sub DataGrid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
ADORst.Close
ADORst.Open "select id ,tex,pic from tbl1 ",adodc, adOpenStatic, adLockOptimistic
   Set DataGrid.DataSource = ADORst
end sub
这样的话在datagrid控件中移动datagrid中就不会显示数据。能加载列pic的图片信息.
而写成ADORst.Open "select id ,tex from tbl1 ",adodc, adOpenStatic, adLockOptimistic
   Set DataGrid.DataSource = ADORst这样的话在datagrid控件中移动datagrid中就可以显示数据。但是这样不能加载列pic的图片信息。
请问我该怎样处理?请指教。

解决方案 »

  1.   

    用mshflexgrid不过不能用绑定,用adodb.stream读出图片,放到网格里吧
      

  2.   

    我想写成ADORst.Open "select id ,tex,pic from tbl1 ",adodc, adOpenStatic, adLockOptimistic
       Set DataGrid.DataSource = ADORst
    不知数据库的内容如何读出到datagrid.
      

  3.   

    其实问题就是:在窗体中有两个DATAGRID控件,一个text文本框,一个image.第一个表与第二个表有关联。第二个表包含text和image图片。我想实现在第一个表中点击,第二个表及文本框、image有变化。在第二个表中点击,文本框和image有变化.不知如何处理?谢谢先。
    在线等待!
      

  4.   

    我做的话就不会定义Connection,Recordset,而是直接使用ADODC控件来绑定数据源,然后把DATAGRID绑定到ADODC控件上面.这样你可以在ADODC的Adodc_WillMove事件(也就是指针移动事件)里刷新image,也就是说一旦记录改变,图像也随之改变.
      

  5.   

    Dim withsevens ADORst As ADODB.Recordset 声明recordset时为withevents的对象。
    然后接收
    sub Recordset _movecomplete事件
    picture.datasourced=rs.field("picture").value
    end sub
      

  6.   

    另外用picturebox来加载图片,不是在datagird的列里。
      

  7.   

    支持楼上的,DATAGRID 不能加载图片,用IMAGE或PICTUREBOX吧,我这里有代码:你自己看着修改吧.
    Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
    Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    Private Const MAX_PATH = 260
    Dim db As ADODB.Connection
    Dim rs As ADODB.Recordset
    Private m_DBConn As ADODB.Connection
    Private Const BLOCK_SIZE = 10000
    Dim er As IntegerPrivate Function TemporaryFileName() As String
    Dim temp_path As String
    Dim temp_file As String
    Dim length As Long
    temp_path = Space$(MAX_PATH)
    length = GetTempPath(MAX_PATH, temp_path)
    temp_path = Left$(temp_path, length)
    temp_file = Space$(MAX_PATH)
    GetTempFileName temp_path, "per", 0, temp_file
    TemporaryFileName = Left$(temp_file, InStr(temp_file, Chr$(0)) - 1)
    End Function
    加如图片
    Private Sub Command2_Click()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    rs.Open "select style# from moudle where style#='" & Text4.Text & "'", m_DBConn
    If rs.EOF = False And rs.BOF = False Then
    MsgBox "该款已经存在!!", , "EFUNNY"
    Text4.SetFocus
    Exit Sub
    Else
    Dim jobid As String
    Dim file_num As String
    Dim file_length As String
    Dim bytes() As Byte
    Dim num_blocks As Long
    Dim left_over As Long
    Dim block_num As Long
    jobid = InputBox("ID", , Text1.Text)
    If Len(jobid) = 0 Then Exit Sub
    dlgpicture.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or cdlOFNExplorer
    dlgpicture.CancelError = True
    dlgpicture.Filter = "Graphics Files|*.bmp;*.ico;*.jpg;*.gif"
    dlgpicture.filename = Text4.Text
    On Error Resume Next
    dlgpicture.ShowOpen
    If Err.Number = cdlCancel Then
    Exit Sub
    ElseIf Err.Number <> 0 Then
    MsgBox "Error " & Format$(Err.Number) & " selecting file." & vbCrLf & Err.Description
    Exit Sub
    End If
    file_num = FreeFile
    Open dlgpicture.filename For Binary Access Read As #file_num
    file_length = LOF(file_num)
    If file_length > 0 Then
    num_blocks = file_length / BLOCK_SIZE
    left_over = file_length Mod BLOCK_SIZE
    'Set rs = New ADODB.Recordset
    'rs.CursorType = adOpenKeyset
    'rs.LockType = adLockOptimistic
    rs.Close
    rs.Open "Select id, Picture,filelength,style#,cat,metaltype,byin,description,datein  FROM moudle", m_DBConn
    rs.AddNew
    rs!ID = jobid
    rs!filelength = file_length
    rs!cat = Combo1(1).Text
    rs!metaltype = Combo1(0).Text
    rs!byin = Combo1(1).Text
    rs!Description = RichTextBox1.Text
    rs!datein = Text2(0).Text
    rs.Fields("style#").Value = Text4.Text
    ReDim bytes(BLOCK_SIZE)
    For block_num = 1 To num_blocks
    Get #file_num, , bytes()
    rs!Picture.AppendChunk bytes()
    Next block_num
    If left_over > 0 Then
    ReDim bytes(left_over)
    Get #file_num, , bytes()
    rs!Picture.AppendChunk bytes()
    rs.Close
    End If
     rs.Update
     Close #file_num
     lstpeople.AddItem jobid
    lstpeople.Text = jobid
    End If
    er = Text1.Text
    Text1.Text = er + 1
    Text4.Text = ""
    Text4.SetFocus
    End If
    End Sub
    显示图片
    Private Sub lstpeople_Click()
    Dim rs As ADODB.Recordset
    Dim bytes() As Byte
    Dim file_name As String
    Dim file_num As Integer
    Dim file_length As Long
    Dim num_blocks As Long
    Dim left_over As Long
    Dim block_num As Long
    Dim hgt As Single
    picperson.Visible = False
    Screen.MousePointer = vbHourglass
    DoEvents
    Set rs = m_DBConn.Execute("SELECT * FROM moudle WHERE id='" & lstpeople.Text & "'", , adCmdText)
    If rs.EOF Then Exit Sub
    If rs!filelength = Null Then Exit Sub
    file_name = TemporaryFileName()
    file_num = FreeFile
    Open file_name For Binary As #file_num
    file_length = rs!filelength
    num_blocks = file_length / BLOCK_SIZE
    left_over = file_length Mod BLOCK_SIZE
    For block_num = 1 To num_blocks
    bytes() = rs!Picture.GetChunk(BLOCK_SIZE)
    Put #file_num, , bytes()
    Next block_num
    If left_over > 0 Then
    bytes() = rs!Picture.GetChunk(left_over)
    Put #file_num, , bytes()
    End If
    Close #file_num
    picperson.Picture = LoadPicture(file_name)
    picperson.Visible = True
    Text1.Text = rs.Fields("id").Value
    rs.Close
    Set rs = m_DBConn.Execute("select * from moudle where id='" & lstpeople.Text & "'", , adCmdText)
    If rs.EOF Then Exit Sub
    If rs.Fields("style#").Value <> "" Then
    Text4.Text = rs.Fields("style#").Value
    Else
    Text4.Text = ""
    End If
    If rs!cat <> "" Then
    Combo1(1).Text = rs!cat
    Else
    Combo1(1).Text = ""
    End If
    If rs!metaltype <> "" Then
    Combo1(0).Text = rs!metaltype
    Else
    Combo1(0).Text = ""
    End If
    If rs!byin <> "" Then
    Combo1(2).Text = rs!byin
    Else
    Combo1(2).Text = ""
    End If
    If rs!Description <> "" Then
    RichTextBox1.Text = rs!Description
    Else
    RichTextBox1.Text = ""
    End If
    If rs!datein <> "" Then
    Text2(0).Text = rs!datein
    Else
    Text2(0).Text = ""
    End If
    Kill file_name
    Screen.MousePointer = vbDefault
    End Sub
      

  8.   

    谁知道willmove的具体用法?ADODC的Adodc_WillMove事件(也就是指针移动事件)里刷新image,就是用image.refresh吗?与datagrid又怎样重新绑定呢?