One, the code is as follows
1 intCode =int. Parse ( This. TextBox1.Text);//Image Encoding2 stringValue = This. FileUpload1.PostedFile.FileName.ToString ();//Picture Path3 stringType = value. Substring (value. LastIndexOf (".") +1);4FileStream fs =File.openread (value);5 byte[] content =New byte[FS. Length];6Fs. Read (Content,0, content. Length);7 FS. Close ();8 9 stringSqlconfrom = system.web.configuration.webconfigurationmanager.connectionstrings["sqlconnectionstrings"]. ToString ();TenSqlConnection con =NewSqlConnection (sqlconfrom); One stringsql ="INSERT into image_table values (' 1 ', @content, @code)"; A -SqlCommand cmd =NewSqlCommand (sql, con); -Cmd. Parameters.Add (NewSqlParameter ("@content", Sqldbtype.image)); theCmd. parameters["@content"]. Value =content; - -Cmd. Parameters.Add (NewSqlParameter ("@code", SqlDbType.Int)); -Cmd. parameters["@code"]. Value =Code; + con. Open (); - intresult =cmd. ExecuteNonQuery (); + if(Result >0) A { atResponse.Write ("Insert Success! "); - } -Con. Close ();
picture binary stored in database
ASP. NET to convert the picture to binary into the database