如何在数据库中存储图像 [英] how to store image in database

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

问题描述

朋友们,我喜欢和vb.net一起工作iam将图像存储到数据库中



但我得到的错误就像





opreater&未定义类型'strin'和'1-dimentional array of byte'





贝娄是我的代码



hi friends iam working with vb.net iam storing image in to database

but iam getting error like


opreater & is not defined for types 'strin' and '1-dimentional array of byte'


bellow is my code

Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("connect").ConnectionString.ToString())
<pre lang="vb">If FileUpload1.HasFile AndAlso FileUpload1.PostedFile IsNot Nothing Then
                Dim File As HttpPostedFile = FileUpload1.PostedFile
                imgByte = New [Byte](File.ContentLength) {}
                File.InputStream.Read(imgByte, 0, File.ContentLength)
            End If
            connection.Open()
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = (insert into Emp1(EmpName,EMpAdd,imPhoto)values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & imgByte & "' )",connection)
            cmd.Connection = connection
            Dim id As Integer = Convert.ToInt32(cmd.ExecuteScalar())</pre>





请你找出解决方案...谢谢你的朋友



will you please find out the solution... thank you fiends

推荐答案

不要这样做!

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

这也有助于解决您的问题...

请看这里:为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ]它使用C#代码,但它解释了你做错了什么,这同样适用于VB。
Don't do that!
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.
It will also help with your problem...
See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] It uses C# code, but it explains what you are doing wrong, and that's just as applicable to VB.


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

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