vb.net数据库图片 vbnet数据库编程

vb.net如何读取oracle数据库中的图片

Public Sub Combo1_Click()

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的黔江网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

Dim adoCnn As ADODB.Connection

Dim rstOra As ADODB.Recordset

Dim intI As Integer

Set adoCnn = New ADODB.Connection

Set rstOra = New ADODB.Recordset

adoCnn.ConnectionString = "Provider=OraOLEDB.Oracle;User ID=dzjc;password=zlkj;Data Source=dzjc_2005;" '读blob字段要用Provider=OraOLEDB.Oracle

adoCnn.CursorLocation = adUseClient

adoCnn.Open

rstOra.CursorLocation = adUseClient

rstOra.ActiveConnection = adoCnn

rstOra.Open "SELECT zp FROM dzjc.dzjc_wfzp WHERE xh = '5'"

'Set Image1.DataSource = rstOra

Set Image1.Picture = PictureFromByteStream(rstOra.Fields("zp").Value)

End Sub

vb.net中,在sql server2000数据库中插入图片,最好有源码,有懂的朋友可以家我QQ1971951508

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ExeDMLSQL()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim strsql As String = "select * from 产品图片 where 序号=1"

Dim objcommand As New SqlCommand(strsql, New SqlConnection(connection))

objcommand.Connection.Open()

Dim myreader As SqlDataReader = objcommand.ExecuteReader()

If myreader.Read() Then

Dim imgInfo() As Byte = myreader("图片")

Dim memoryStream As New MemoryStream(imgInfo)

PictureBox1.Image = Image.FromStream(memoryStream)

End If

End Sub

Private Sub ExeDMLSQL()

Dim st As New FileStream("D:\1.png", FileMode.Open, FileAccess.Read)

Dim mbr As New BinaryReader(st)

Dim buffer(st.Length) As Byte

mbr.Read(buffer, 0, CInt(st.Length))

st.Close()

InsertImage(buffer)

End Sub

Private Sub InsertImage(ByVal buffer() As Byte)

Dim cn As New SqlConnection(connection)

cn.Open()

Dim cmd As New SqlCommand("SaveImg", cn)

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = 1

cmd.Parameters.Add("@image", SqlDbType.Image).Value = buffer

cmd.ExecuteNonQuery()

MsgBox("Image inserted.")

cn.Close()

End Sub

SaveImg是一个存储过程:

ALTER PROCEDURE dbo.SaveImg

@name AS int,

@image AS IMAGE

AS

INSERT INTO 产品图片 (序号, 图片)

VALUES (@name, @image)

VB.NET从数据库中读取图片出现“Parameter is not valid”

Dim curSqlstr As String = "INSERT INTO Picture(picture_id, picture_area)" _

"VALUES('" (i + 1).ToString() "','@picture_area ')"

你看这句中的,'@picture_area ')",多个单引号了,被当成VARCHAR处理了.去了单引号才是变量.


网页题目:vb.net数据库图片 vbnet数据库编程
网页路径:http://myzitong.com/article/doipsgi.html