大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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
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)
Dim curSqlstr As String = "INSERT INTO Picture(picture_id, picture_area)" _
"VALUES('" (i + 1).ToString() "','@picture_area ')"
你看这句中的,'@picture_area ')",多个单引号了,被当成VARCHAR处理了.去了单引号才是变量.