Sir,
when I am executing an above code and click on button to insert data is shows ann error message as: System.Data.SqlClient.SqlException: Must declare the scalar variable "@imagefile"
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Try
If fileupload1.HasFile Then
'getting length of uploaded file
Dim length As Integer = fileupload1.PostedFile.ContentLength
'create a byte array to store the binary image data
Dim imgbyte As Byte() = New Byte(length - 1) {}
'store the currently selected file in memeory
Dim img As HttpPostedFile = fileupload1.PostedFile
'set the binary data
img.InputStream.Read(imgbyte, 0, length)
Dim imagename As String = textbox1.Text.trim
'use the web.config to store the connection string
Dim connection As New SqlConnection(constr)
connection.Open()
Dim cmd As New SqlCommand("INSERT INTO imgtab(imagename,imagefile) VALUES (@imagename,@imagefile)", connection)
cmd.Parameters.AddWithValue("@imagefile", imagename)
cmd.Parameters.AddWithValue("@imagefile", imgbyte)
Dim count As Integer = cmd.ExecuteNonQuery()
connection.Close()
label1.Text = "Image saved"
bindgrid()
End If
Catch ex As Exception
label1.Text = ex.ToString
End Try
End Sub