Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

memanggil Image dari access

kalo mau menampilkan image dari access untuk ditampilkan dipicturebox gimana ya caranya? aku pakai vb.net, tipe datanya byte(OLE Object).
kalo bisa source codenya ya...?

Comments

  • Mungkin class di bawah bisa membantu, walau pakai cara dataset.
    Blob merupakan byte yang di simpan ke database dan kita men-handle-nya dalam byte(chunks) juga.
    Ada beberapa cara untuk itu dan yang paling mudah dengan menggunakan dataset object ini.
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.IO
    Imports System.Drawing
    
    Public Class ImageDb
    
        Private strConn As String = "Provider=microsoft.jet.oledb.4.0; data source=" & Application.StartupPath & "..db.mdb"
        Private strSql As String = "SELECT img FROM table1;"
        Private strTable As String = "table1"
        Private strField As String = "img"
    
        Private dsImage As DataSet
    
        Private Sub LoadImageDataset()
            dsImage = Nothing
    
            Using conn As New OleDbConnection(strConn)
                Using da As New OleDbDataAdapter(strSql, conn)
                    Using cb As New OleDbCommandBuilder(da)
                        conn.Open()
                        dsImage = New DataSet()
                        da.Fill(dsImage, strTable)
                        conn.Close()
                    End Using
                End Using
            End Using
        End Sub
    
        Private Sub InitDs()
            If dsImage Is Nothing Then
                LoadImageDataset()
            End If
        End Sub
    
        Private Function GetDbImage(ByVal i As Integer) As Byte()
            InitDs()
            Dim rw As DataRow = dsImage.Tables(strTable).Rows(i)
            Dim theImage() As Byte = CType(rw(strField), Byte())
            Return theImage
        End Function
    
        Public Function GetTotalImage() As Integer
            InitDs()
            Return dsImage.Tables(strTable).Rows.Count
        End Function
    
        'Put Image into Picture Control
        Public Function GetImage(ByVal i As Integer) As Image
            Dim theImage() As Byte = GetDbImage(i)
            Return Image.FromStream(New IO.MemoryStream(theImage))
        End Function
    
        'Write Image File to FileSystem
        Public Sub WriteFileImage(ByVal i As Integer, ByVal FileName As String)
            Dim theImage() As Byte = GetDbImage(i)
            Using fs As New FileStream(FileName, IO.FileMode.OpenOrCreate, FileAccess.Write)
                fs.Write(theImage, 0, UBound(theImage))
                fs.Close()
            End Using
        End Sub
    
        'Save Image From File to Database
        Public Sub SaveImage(ByVal FileName As String)
            Dim ds As New DataSet
    
            Using conn As New OleDbConnection(strConn)
                Using da As New OleDbDataAdapter(strSql, conn)
                    Using cb As New OleDbCommandBuilder(da)
                        Using fs As New FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Read)
                            Dim arrImage(CInt(fs.Length)) As Byte
                            fs.Read(arrImage, 0, CInt(fs.Length))
                            fs.Close()
    
                            conn.Open()
                            da.Fill(ds, strTable)
                            Dim rw As DataRow = ds.Tables(strTable).NewRow()
                            rw(strField) = arrImage
                            ds.Tables(strTable).Rows.Add(rw)
                            da.Update(ds, strTable)
                            conn.Close()
                        End Using
                    End Using
                End Using
            End Using
    
            dsImage = Nothing
        End Sub
    
    End Class
    
  • tanya donk
    bisa ga kalo saya ga pake dataset,
    pakai benda yg lain?

    misalnya bisa ga...
    pakai stored procedure
    dan masukin oledbtype.binary ?
  • mungkin ini bisa membantu
    Using conn As New OleDbConnection(strConn)
    	Using cmd As New OleDbCommand("INSERT INTO table1 (img) VALUES (@image);", conn)
    		Using fs As New FileStream(FileName, FileMode.Open, FileAccess.Read)
    			Dim arrImage(CInt(fs.Length)) As Byte
    			fs.Read(arrImage, 0, CInt(fs.Length))
    			fs.Close()
    
    			Dim p As New OleDbParameter("@image", _
    						OleDbType.LongVarBinary, _
    						arrImage.Length, _
    						ParameterDirection.Input, _
    						False, _
    						0, _
    						0, _
    						Nothing, _
    						DataRowVersion.Current, _
    						arrImage)
    			cmd.Parameters.Add(p)
    
    			conn.Open()
    			cmd.ExecuteNonQuery()
    			conn.Close()
    		End Using
    	End Using
    End Using
    
Sign In or Register to comment.