Berikut ini adalah contoh mengambil gambar dari database
- datatype di database adalah image.
- data ditampilkan kemudian ditampung kedalam dataset
- tarik picture box ke form anda
Dim cn As New OdbcConnection("Koneksi Sql Server anda")
Dim cm As New OdbcCommand
Dim dsFoto As New DataSet
Dim daFoto As New OdbcDataAdapter
Dim builder As OdbcCommandBuilder
dsFoto.Tables.Clear()
Try
cn.Open()
With cm
.Connection = cn
.CommandType = CommandType.Text
.CommandText = "SELECT fotosaya FROM tblFoto where kode=? "
.Parameters.Add("", OdbcType.VarChar).Value ="2101251"
End With
daFoto.SelectCommand = cm
builder = New OdbcCommandBuilder(daFoto)
daFoto.Fill(dsFoto, "dtfoto")
Catch ex As Exception
Throw ex
End Try
Dim dt As DataTable = dsFoto.Tables(0)
If dt.Rows.Count > 0 Then
bite = CType(dt.Rows(0).Item(0), Byte())
Dim ma As New IO.MemoryStream(bite)
PhotoPictureBox.Image = Image.FromStream(ma)
PhotoPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
Else
PhotoPictureBox.Image = Nothing
End If
Demikian semoga artikel ini berguna.
- datatype di database adalah image.
- data ditampilkan kemudian ditampung kedalam dataset
- tarik picture box ke form anda
Dim cn As New OdbcConnection("Koneksi Sql Server anda")
Dim cm As New OdbcCommand
Dim dsFoto As New DataSet
Dim daFoto As New OdbcDataAdapter
Dim builder As OdbcCommandBuilder
dsFoto.Tables.Clear()
Try
cn.Open()
With cm
.Connection = cn
.CommandType = CommandType.Text
.CommandText = "SELECT fotosaya FROM tblFoto where kode=? "
.Parameters.Add("", OdbcType.VarChar).Value ="2101251"
End With
daFoto.SelectCommand = cm
builder = New OdbcCommandBuilder(daFoto)
daFoto.Fill(dsFoto, "dtfoto")
Catch ex As Exception
Throw ex
End Try
Dim dt As DataTable = dsFoto.Tables(0)
If dt.Rows.Count > 0 Then
bite = CType(dt.Rows(0).Item(0), Byte())
Dim ma As New IO.MemoryStream(bite)
PhotoPictureBox.Image = Image.FromStream(ma)
PhotoPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
Else
PhotoPictureBox.Image = Nothing
End If
Demikian semoga artikel ini berguna.
Post a Comment for "Menampilkan Gambar atau foto Pada Picture Box dengan VB.net Dari Database SQL Server 2008"