I want to add image from FileUpload to a local SQL Server database in ASP.NET.
I have read many same questions, but they didn't help me:(
int length = FileUpload.PostedFile.ContentLength;
byte[] picSize = new byte[length];
HttpPostedFile uplImage= FileUpload.PostedFile;
uplImage.InputStream.Read(picSize, 0, length);
SqlCommand com = new SqlCommand("INSERT INTO [Table] (Name, Picture) values (@Name, @Picture)", con);
com.Parameters.AddWithValue("@Name", TextName.Text);
com.Parameters.AddWithValue("@Picture", picSize);
com.ExecuteNonQuery();
So if I simply add column Name - all okay. But when I want also add image to database there is mistake:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Incorrect syntax near the keyword 'Picture'.
In my local database Picture have an image type. Please help me.
.AddWithValue()- it can lead to unexpected and surprising results...imagewill be removed in a future version of SQL Server. Avoid using this data type in new development work, and plan to modify applications that currently use them. Usevarbinary(max)instead. See details here