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 I have many read the same question, but they did not help me: ( So if I just add the column 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 You have to capture and handle it: FileUpload .
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 ();
name - OK, but whenever I want to add an image to the database Mr. I do not fault:
image in the keyword. Please help me.
< 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
Post a Comment