-
- private void save(string nomcomplet)
- {
-
- //Avec la class FileInfo on peut recuperer la taille de l'image
- FileInfo fiImage=new FileInfo(nomcomplet);
-
- //On declare un tableau de la taille de l'image
- this.m_lImageFileLength=fiImage.Length;
- m_barrImg=new byte[Convert.ToInt32(this.m_lImageFileLength)];
-
- //Avec l'objet FileStream on remplit le tableau de byte
- FileStream fs = new FileStream(nomc,FileMode.Open,FileAccess.Read,FileShare.Read);
- int iBytesRead=fs.Read(m_barrImg,0,Convert.ToInt32(this.m_lImageFileLength));
- fs.Close();
-
- //On ouvre la connection
- SqlConnection myConnection = new SqlConnection();
- myConnection.ConnectionString = ConfigurationSettings.AppSettings["Connect"];
-
- //On specifie que c'est une procedure stockee
- SqlCommand myCommand = new SqlCommand("SP_StockImage",myConnection);
- myCommand.CommandType = CommandType.StoredProcedure;
-
- //Parametre
- myCommand.Parameters.Add("@Name", SqlDbType.VarChar, 50);
- myCommand.Parameters.Add("@Picture", SqlDbType.Image);
-
- //Les valeurs pour les parametres de la procedure stockee
- myCommand.Parameters["@Name"].Value = Label1.Text;
- myCommand.Parameters["@Picture"].Value = m_barrImg;
-
- //Parametre de sortie
- SqlParameter renvoitID = new SqlParameter("@ID_Recup",SqlDbType.Int, 4);
- renvoitID.Direction = ParameterDirection.Output;
- myCommand.Parameters.Add(renvoitID);
-
- //Open connection
- myConnection.Open();
-
- //execution de la procedure stockee
- int id = Convert.ToInt32(myCommand.ExecuteScalar());
-
- //Close connection
- myConnection.Close();
-
- //On redirige
- Response.Redirect("Affiche.aspx?lastID="+id);
- }
private void save(string nomcomplet)
{
//Avec la class FileInfo on peut recuperer la taille de l'image
FileInfo fiImage=new FileInfo(nomcomplet);
//On declare un tableau de la taille de l'image
this.m_lImageFileLength=fiImage.Length;
m_barrImg=new byte[Convert.ToInt32(this.m_lImageFileLength)];
//Avec l'objet FileStream on remplit le tableau de byte
FileStream fs = new FileStream(nomc,FileMode.Open,FileAccess.Read,FileShare.Read);
int iBytesRead=fs.Read(m_barrImg,0,Convert.ToInt32(this.m_lImageFileLength));
fs.Close();
//On ouvre la connection
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = ConfigurationSettings.AppSettings["Connect"];
//On specifie que c'est une procedure stockee
SqlCommand myCommand = new SqlCommand("SP_StockImage",myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
//Parametre
myCommand.Parameters.Add("@Name", SqlDbType.VarChar, 50);
myCommand.Parameters.Add("@Picture", SqlDbType.Image);
//Les valeurs pour les parametres de la procedure stockee
myCommand.Parameters["@Name"].Value = Label1.Text;
myCommand.Parameters["@Picture"].Value = m_barrImg;
//Parametre de sortie
SqlParameter renvoitID = new SqlParameter("@ID_Recup",SqlDbType.Int, 4);
renvoitID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(renvoitID);
//Open connection
myConnection.Open();
//execution de la procedure stockee
int id = Convert.ToInt32(myCommand.ExecuteScalar());
//Close connection
myConnection.Close();
//On redirige
Response.Redirect("Affiche.aspx?lastID="+id);
}