
28/02/2008, 08:21
|
 | Colaborador | | Fecha de Ingreso: septiembre-2007 Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 17 años, 5 meses Puntos: 87 | |
Re: Manejo de Imagenes SQL-.NET Necesitas u campo BLOB, la escritura es simple pero la lectura un poco mas complicada
un ejemplo de esto es
SqlCommand com = new SqlCommand("insert into StudentPhoto values(@roll,@photo)", con);
com.Parameters.Add(new SqlParameter("@roll", SqlDbType.Int));
com.Parameters.Add(new SqlParameter("@photo", SqlDbType.Image));
FileInfo fi = new FileInfo(archivoruta);
int imgSize = fi.Length;
Stream fs = new FileStream(archivoruta, FileAccess.Read);
byte[] imgContent = new byte[imgSize];
imgStream.Read(imgContent, 0, imgSize);
com.Parameters["@roll"].Value = Int32.Parse(TxtRoll.Text);
com.Parameters["@photo"].Value = imgContent;
con.Open();
com.ExecuteNonQuery();
con.Close();
Eso fue guardado
Esto es lectura
SqlCommand com = new SqlCommand("select photo from studentphoto where roll=" + Int32.Parse(ComboRoll.SelectedItem.Text), con);
con.Open();
SqlDataReader rd=com.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
System.Data.SqlTypes.SqlBytes photo=rd.GetSqlBytes(0);
Bitmap bmp = new Bitmap(photo.Stream);
FileStream fs=new FileStream("c:\\abc.jpg",FileMode.Create);
bmp.Save(fs,System.Drawing.Imaging.ImageFormat.Jpe g);
StudImage.ImageUrl = "c:\\abc.jpg";
}
}
rd.Close();
con.Close();
Saludos
peter |