Click here to Skip to main content
15,894,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
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
Posted
Updated 1-Sep-14 1:54am
v3
Comments
Kornfeld Eliyahu Peter 1-Sep-14 7:42am    
Please do not SHOUT - it's considered rude...
[no name] 1-Sep-14 7:43am    
Do you always scream at the people that you want to help you? Use a parameterized query or fix your SQL statement.
Kornfeld Eliyahu Peter 1-Sep-14 7:51am    
Please! No 'or'! Parameterized query. Period!

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900