Cool that worked, maybe you could help me with the overall problem also. I am trying to insert a picture into my database. Now that I have the invalid column name solved I have another error. The error is stating that I cannot insert a null into the column and I am sure that I'm not inserting a null type. Here is the code and the error is attached.

Public Sub Button2_Click(ByVal objSender As Object, ByVal objArgs As EventArgs)
        Dim intLength As Integer
        Dim ByteSize As Byte()
        Dim fileName As String = FileUpload1.PostedFile.FileName
        Dim imgType = FileUpload1.PostedFile.ContentType
        intLength = Int32.Parse(FileUpload1.PostedFile.InputStream.Length)
        ReDim ByteSize(intLength)
        FileUpload1.PostedFile.InputStream.Read(ByteSize, 0, intLength)
        Doc2SQLServer(ByteSize, intLength)
    End Sub
    Public Function Doc2SQLServer(ByVal Content As Byte(), ByVal Length As Integer) As Boolean
        Dim ConnString As String
        ConnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\inetpub\wwwroot\KiKoGraphics\App_Data\aspnetdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        Dim sqlConn As New SqlConnection(ConnString)
        Dim sqlCom As New SqlCommand()
        sqlCom.Connection = sqlConn
        sqlCom.CommandText = "INSERT INTO ImageTable (DatabaseImage) VALUES (@Photo)"
        sqlCom.Parameters.Add("@Photo", Data.SqlDbType.Image)
        sqlCom.Parameters("@Photo").Value = Content
    End Function
8 Years
Discussion Span
Last Post by a496761

It's usually best practice to store the image name or location in the database and use that on your front-end to display the image. Is there a reason you can't do that in this instance?


Hey thanks for responding. I will have the image name and alot more other information stored with the image, But to understand the process of storing an image in a database the other information is not needed. Can you help me out?

Thanks in advance.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.