1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
[SqlProcedure]
public static void PI_INSERT_PERSONNEL_MAP_PHOTOS(string pConnectionString, string pID, string pPhotoFile)
{
try
{
if (File.Exists(pPhotoFile))
{
FileStream photoStream = new FileStream(pPhotoFile, FileMode.Open, FileAccess.Read);
int len = Convert.ToInt32(photoStream.Length);
byte[] photoFile = new byte[len];
photoStream.Read(photoFile, 0, len);
photoStream.Close();
SqlConnection connection = new SqlConnection(pConnectionString);
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("insert into PERSONNEL_PHOTOS "
+ "(id, pho_file) values (@id, @photoFile)", connection);
cmd.Parameters.AddWithValue("@id", pID);
cmd.Parameters.AddWithValue("@photoFile", photoFile);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
else
{
try
{
File.GetAttributes(pPhotoFile);
}
catch (Exception ex)
{
throw;
}
}
}
catch (Exception ex)
{
SqlContext.Pipe.Send("Message: " + ex.Message);
}
} |
Partager