将图像写入sql-Database [英] Write Image to sql-Database
本文介绍了将图像写入sql-Database的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim img 作为 字节()
Dim fs As 新 FileStream( c:\ temp \ MyZipFile.zip,FileMode.Open,FileAccess.Read)
Dim br As 新 BinaryReader(fs)
img = br.ReadBytes((Int(fs.Length)))
sQry = 插入st_image& vbCrLf
sQry = sQry& (DOC_OBJECT_ID,DOC_IMAGE,DOC_COMPRESSED)& vbCrLf
sQry = sQry& 值& vbCrLf
sQry = sQry& (& vbCrLf
sQry = sQry& cMain.NewSystemCounter& ,@ IMG
sQry = sQry& ,
sQry = sQry& -1& vbCrLf
sQry = sQry& ) & vbCrLf
尝试
Dim cmdAdd 作为 新 OleDbComman
cmdAdd。 Connection = conn1
cmdAdd.CommandText = sQry
cdAdd.Parameters.AddWithValue( @IMG,img)
cmdAdd.ExecuteNonQuery()
Catch ex As 异常
MsgBox(ex.Message)
结束 尝试
启动程序时,我总是收到消息必须声明varbele'@ IMG'
我做错了什么。
我使用Visual Basic 2012 WPF和SQl-Server 2005.
sQry =插入到st_image(DOC_OBJECT_ID,DOC_IMAGE,DOC_COMPRESSED)值( 13080002756,@ IMG,-1)
谢谢。
解决方案
尝试改变
cdAdd.Parameters.AddWithValue( @ IMG,img)
to
cdAdd.Parameters.Add( @ IMG,SQLDbType.Image).Value = img;
我不知道这是否是您创建问题时的错误,但请查看以下内容(来自您的问题):
cmdAdd.CommandText = sQry
cdAdd.Parameters.AddWithValue( @ IMG,img)$ p您键入 cmdAdd 的第一行上的$ p>
,但是在键入 cdAdd 的第二行,我建议您更正该类型它存在于您的代码中,因为它可能是问题。
谢谢你或者你的答案,
但我仍然收到错误必须声明变量'@IMG'
Dim img As Byte()
Dim fs As New FileStream("c:\temp\MyZipFile.zip", FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
img = br.ReadBytes((Int(fs.Length)))
sQry = "Insert into st_image " & vbCrLf
sQry = sQry & "(DOC_OBJECT_ID, DOC_IMAGE, DOC_COMPRESSED)" & vbCrLf
sQry = sQry & "Values" & vbCrLf
sQry = sQry & "(" & vbCrLf
sQry = sQry & cMain.NewSystemCounter & ", @IMG"
sQry = sQry & ", "
sQry = sQry & " -1" & vbCrLf
sQry = sQry & ")" & vbCrLf
Try
Dim cmdAdd As New OleDbComman
cmdAdd.Connection = conn1
cmdAdd.CommandText = sQry
cdAdd.Parameters.AddWithValue("@IMG", img)
cmdAdd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
When start the program i always get the message "Must declare variabele '@IMG'"
What i doing wrong.
I use Visual Basic 2012 WPF and SQl-Server 2005.
sQry = "Insert into st_image (DOC_OBJECT_ID, DOC_IMAGE, DOC_COMPRESSED) Values ( 13080002756, @IMG, -1 )"
Thank you.
解决方案
Try to change
cdAdd.Parameters.AddWithValue("@IMG", img)
to
cdAdd.Parameters.Add("@IMG",SQLDbType.Image).Value = img;
I don't know if this is a typo from when you created the question but look at the following (from your question):
cmdAdd.CommandText = sQry cdAdd.Parameters.AddWithValue("@IMG", img)
on the first line you have typed cmdAdd but on the second line you have typed cdAdd, I suggest you correct that type if it exists in your code as it could well be the issue.
Thank you for your answer,
But still i get the error "Must declare variabele '@IMG'"
这篇关于将图像写入sql-Database的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文