本文介绍了从vb.net中的访问数据库到图片框中获取图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉如何从数据库(访问)获取图像到

视觉基本图片框控件。我一直在使用的代码是

,但它给了我无效的参数错误....


Dim connection As New OleDb.OleDbConnection()

Dim cmd As新OleDb.OleDbCommand()

cmd.CommandText ="选择ID,名称,描述,图片来自

MASTER其中ID喜欢''' &安培;修剪(cmbID.Text)& "''"

cmd.Connection = connection

Dim myReader作为OleDb.OleDbDataReader

cmd.CommandType = CommandType.Text

openOLEDBconnection(SQL_CONNECTION_STRING,连接)

myReader =

cmd.ExecuteReader(CommandBehavior.CloseConnection)

myReader.Read ()

txtId.Text = myReader(0)

txtName.Text = myReader(1).ToString()

txtDescription.Text = myReader(2).ToString()

如果不是IsDBNull(myReader(3))那么

试试

试试

Dim a(myReader.GetBytes(3,0,Nothing,0,

Integer.MaxValue) - 1)By Byte

myReader.GetBytes(3,0, a,0,a.Length)

Dim b As New MemoryStream(a)

with pbImage

.Image = image.FromStream(b )

.SizeMode =

PictureBoxSizeMode.CenterImage

.BorderStyle = BorderStyle.Fixed3D



Catch exp As Exception

MsgBox(exp.Message)

结束尝试

Catch exp As System.InvalidCastException

MsgBox(exp.Message)

结束尝试

结束如果

结束时

myReader.Close()

can anybody tell how to fetch image from database(access) to the
visual basic picture box control. the code i have been using is as
below but it gives me invalid paramter error....

Dim connection As New OleDb.OleDbConnection()
Dim cmd As New OleDb.OleDbCommand()
cmd.CommandText = "select ID,Name,Description,Image from
MASTER where ID like ''" & Trim(cmbID.Text) & "''"
cmd.Connection = connection
Dim myReader As OleDb.OleDbDataReader
cmd.CommandType = CommandType.Text
openOLEDBconnection(SQL_CONNECTION_STRING, connection)
myReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
While myReader.Read()
txtId.Text = myReader(0)
txtName.Text = myReader(1).ToString()
txtDescription.Text = myReader(2).ToString()
If Not IsDBNull(myReader(3)) Then
Try
Try
Dim a(myReader.GetBytes(3, 0, Nothing, 0,
Integer.MaxValue) - 1) As Byte
myReader.GetBytes(3, 0, a, 0, a.Length)
Dim b As New MemoryStream(a)
With pbImage
.Image = image.FromStream(b)
.SizeMode =
PictureBoxSizeMode.CenterImage
.BorderStyle = BorderStyle.Fixed3D
End With
Catch exp As Exception
MsgBox(exp.Message)
End Try
Catch exp As System.InvalidCastException
MsgBox(exp.Message)
End Try
End If
End While
myReader.Close()

推荐答案





这篇关于从vb.net中的访问数据库到图片框中获取图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 08:39