如何保存图像Blob [英] how to save image Blob

查看:84
本文介绍了如何保存图像Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要使用vb .net 2008将图像存储为sql server 2005中的Blob文件。我的功能是Oledb。

 Private Sub cmdsave_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理cmdsave.Click 

Dim fstream As FileStream
Dim imgdata As Byte()
Dim data As Byte()
Dim finfo As FileInfo
finfo = New FileInfo(txtpic.Text)
Dim numbyte As Long
Dim br As BinaryReader
numbyte = finfo.Length
fstream =新FileStream(txtpic.Text,FileMode.Open,FileAccess.Read)
br =新BinaryReader(fstream)
data = br.ReadBytes (numbyte)
'MsgBox(data.ToString)
imgdata = data

如果不是IsNumeric(txtmobile.Text)那么
MsgBox(Mobile No应该是数字!!,MsgBoxStyle.Exclamation,Uparjon HRM& Payroll)
退出Sub
结束如果
如果sqlDT.Rows.Count> 0然后
qlSTR =INSERT INTO TBL_CompanyInf(BussName,BussNameB,BussLocation,BussLocationB,EstDate,BussContact,Tin,Email_Address,Website,logo)& _
VALUES('" txtcomp.Text&',_
&'& txtcompB.Text&',_
& '& txtloc.Text&',_
&'& txtlocB.Text&',_
&'& dtp1.Text& ;',_
&'& txtmobile.Text&',_
&'& txtfex.Text&',_
&'& txtemil.Text&',_
&'& txtweb.Text&',_
&'& ; txtpic.Text&',_
&'& imgdata(0)&')
'MsgBox(sqlSTR)
ExecuteSQLQuery(sqlSTR)
结束子



现在我的需要urg ent help

解决方案

按照以下链接进行讨论。



如何在SQL Server表中存储或保存图像 [ ^ ]

请不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。



这也将解决您的问题。


Hi,

I need to store image as a Blob file in sql server 2005 using vb .net 2008. My cannection is Oledb.

Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
          
        Dim fstream As FileStream
        Dim imgdata As Byte()
        Dim data As Byte()
        Dim finfo As FileInfo
        finfo = New FileInfo(txtpic.Text)
        Dim numbyte As Long
        Dim br As BinaryReader
        numbyte = finfo.Length
        fstream = New FileStream(txtpic.Text, FileMode.Open, FileAccess.Read)
        br = New BinaryReader(fstream)
        data = br.ReadBytes(numbyte)
        'MsgBox(data.ToString)
        imgdata = data

        If Not IsNumeric(txtmobile.Text) Then
            MsgBox("Mobile No should be numeric !!", MsgBoxStyle.Exclamation, "Uparjon HRM & Payroll")
            Exit Sub
        End If
        If sqlDT.Rows.Count > 0 Then
qlSTR = "INSERT INTO TBL_CompanyInf (BussName, BussNameB, BussLocation, BussLocationB, EstDate, BussContact, Tin, Email_Address, Website, logo) " & _
                     "VALUES ('" & txtcomp.Text & "', " _
                             & "'" & txtcompB.Text & "', " _
                             & "'" & txtloc.Text & "', " _
                             & "'" & txtlocB.Text & "', " _
                             & "'" & dtp1.Text & "', " _
                             & "'" & txtmobile.Text & "', " _
                             & "'" & txtfex.Text & "', " _
                             & "'" & txtemil.Text & "', " _
                             & "'" & txtweb.Text & "', " _
                             & "'" & txtpic.Text & "', " _
                            & "'" & imgdata(0) & "')"
            'MsgBox(sqlSTR)
            ExecuteSQLQuery(sqlSTR)
End sub 


now my need urgent help

解决方案

Follow below link it discuss the same.

How to Store or Save Image in SQL Server table[^]


Please, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

That will also solve your problem.


这篇关于如何保存图像Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆