VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • vb.net实现Datagridview控件显示数据库中的图片

vb.net实现Datagridview控件显示数据库中的图片,以下是具体的代码与示例:
 
 
 
Imports System.Data.SqlClient
 
Imports System.Data.Sql
 
Imports System.Drawing
 
Imports System.IO
 
Imports System.Drawing.Drawing2D
 
代码:
 
    Dim MySipImage As Bitmap
 
    Dim MyBipImage As Bitmap
 
    Dim MySipDImage As Bitmap
 
    Dim MyBipDImage As Bitmap
 
 
 
 
 
' 数据库操作Image
 
    Private Sub selectgg()
 
        Try
 
            objDataSet = New DataSet()
 
            Dim ProcStr As String = "procg" '存储过程名
 
            Dim tableName As String = "g" '表名
 
 
 
            objCommand = New SqlCommand(ProcStr, conSql)
 
            objDataAdapter = New SqlDataAdapter(objCommand)
 
            objDataAdapter.Fill(objDataSet, tableName)
 
            gvData.DataSource = objDataSet.Tables(tableName)
 
            If objDataSet.Tables(tableName).Rows.Count > 0 Then
 
                Dim MyData() As Byte
 
                MyData = objDataSet.Tables(tableName).Rows(0)("g")
 
                Dim K As Long
 
                K = UBound(MyData)
 
                Dim w As New MemoryStream(MyData)
 
                Try
 
                    MyBipImage = New Bitmap(System.Drawing.Image.FromStream(w), PicImage.Width, PicImage.Height)
 
                    Me.PicImage.Image = MyBipImage
 
                Catch ex As Exception
 
                    MsgBox(ex.Message)
 
                End Try
 
 
 
 
 
                Dim MyDataD() As Byte
 
                MyDataD = objDataSet.Tables(tableName).Rows(0)("d")
 
                Dim KD As Long
 
                KD = UBound(MyDataD)
 
                Dim wD As New MemoryStream(MyDataD)
 
                Try
 
 
 
                    MyBipDImage = New Bitmap(System.Drawing.Image.FromStream(wD), PicImage.Width, PicImage.Height)
 
 
 
                    Me.PicDImage.Image = MyBipDImage
 
                Catch ex As Exception
 
                    MsgBox(ex.Message)
 
                End Try
 
 
 
            End If
 
        Catch ex As Exception
 
            MessageBox.Show(ex.Message)
 
        End Try
 
 
 
    End Sub
————————————————
版权声明:本文为CSDN博主「lhm19810710」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lhm19810710/article/details/5974991

相关教程