c# - Insert image to local SQL Server database in ASP.NET -


I want to add an image from the local SQL Server database in ASP.NET to FileUpload .

I have many read the same question, but they did not help me: (

  int length = FileUpload.PostedFile.ContentLength; byte [] picSize = new byte [ length]; HttpPostedFile uplImage = FileUpload.PostedFile; uplImage.InputStream.Read (picSize, 0, length); SqlCommand comm = Insert new SqlCommand ( "[table] (name, image) values ​​(@Name, @Picture) in" thief); com.Parameters.AddWithValue ( "@ name", TextName.Text); com.Parameters.AddWithValue ( "@ picture", picSize); com.ExecuteNonQuery ();   

So if I just add the column name - OK, but whenever I want to add an image to the database Mr. I do not fault:

A type of exception 'System.Data. In SqlClient.SqlException' System.Data.dll but user code

Additional Information Was not handled: Type the wrong syntax '. Picture'

in my local database image in a image in the keyword. Please help me.

You have to capture and handle it:

 < Code> int length = FileUpload.PostedFile.ContentLength; Byte [] picSize = new byte [length]; HTTP posted file appeal IIMAG = file upload. Posted file; UplImage.InputStream.Read (picSize, 0, Length); Using (SqlConnection con = new SqlConnection (connectionstring)) put {SqlCommand comm = new SqlCommand ( "[Table] (name, image) values ​​(@Name, @Picture)", con); Try {com.Parameters.AddWithValue ("@Name", TextName.Text); Com.Parameters.AddWithValue ("@Picture", picSize); Com.ExecuteNonQuery (); } Catch (SqlException ex) to {(int i = 0; i & LT; ex.Errors.Count; i ++) {errorMessages.Append ( "index #" + i + "\ n" + "message:" + Ex.Errors [I]. Message + "\ n" + "Linenumber:" + East. Errs [i] .LineNumber + "\ n" + "Source:" + Former .arter [i]. Source + "\ N "+" Process: "+ Pre. Errors [i]. Process +" \ n "); } Console.light line (error message. Toastring ()); }}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -