1.读图片到byte[]; int fLen = IMAGE.PostedFile.ContentLength; byte[] sIMAGE= new byte[fLen]; IMAGE.PostedFile.InputStream.Read(sIMAGE,0,fLen); 2.写入数据库时; if(p_MPhotol.Length>0){com.Parameters.Add("@imgMPhotol",p_MPhotol);} else { com.Parameters.Add("@imgMPhotol",SqlDbType.Image); //为空的时候一定要先加一个SqlDbType.Image类型参数,再给它DBNull.Value才行 com.Parameters["@imgMPhotol"].Value = DBNull.Value; } |
|