Having trouble with a simple database command I keep getting the error invalid column name and I cant seem to figure it out. Please help me figure out some possible problems Thanks.

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.CommandText = "INSERT INTO ImageTable ('DatabaseImage') VALUES ('@Photo')"
        sqlCom.Connection = sqlConn
        sqlCom.Parameters.Add("@Photo", Data.SqlDbType.Image)
        sqlCom.Parameters("@Photo").Value = Content
        sqlConn.Open()
        sqlCom.ExecuteNonQuery()
        sqlConn.Close()

Recommended Answers

All 10 Replies

Hi - Check the spelling on your SQL database, this is probably the issue. An invalid column name means the column simply doesn't exist as stated.

Also, try a test. What happens when you run the query:

Select DatabaseImage from ImageTable

Best/Eric


P.S. If this helped, give me some points and marked as solved! :-)

Hey thanks for responding. The spelling is correct thats why I don't understand the error and I ran the query you suggested, I also ran an update query and in both cases the application did not crash (give me and error). What else could it be?

Can you please provide the exact exception being thrown?

(stacktrace, too)

Here is the stack trace.

That didnt work as expected, try this.

Ah, get rid of the ' around databaseimage

Also, I am pretty sure you need to get rid of the ' around @Photo...

I would recommend not storing images into the database, but rather store the relative path of the image in the database. I think you will find this much better.

"INSERT INTO ImageTable (DatabaseImage) VALUES ('@Photo')"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.