Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save orlodax/f4450e9d4197aff873431a94c8b2635f to your computer and use it in GitHub Desktop.

Select an option

Save orlodax/f4450e9d4197aff873431a94c8b2635f to your computer and use it in GitHub Desktop.
Blob SQL
using (MySqlConnection conn = new MySqlConnection(ConnectionString))
{
MySqlCommand cmd = new MySqlCommand(String.Format("INSERT INTO foto (idcantiere,data,immagine) VALUES ('{0}',{1},@Image);", idCantiere, DateToUnix(data.Date)), conn);
MySqlParameter paramImage = new MySqlParameter("@Image", MySqlDbType.LongBlob, foto.Immagine.Length);
paramImage.Value = foto.Immagine;
cmd.Parameters.Add(paramImage);
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch (MySqlException e)
{
OnMySqlError(new MySqlErrorEventArgs(e));
conn.Close();
}
}
//basic MySQL reading method
public async override void ExecuteQuery(string query)
{
using (MySqlConnection conn = new MySqlConnection(ConnectionString))
{
MySqlCommand cmd = new MySqlCommand(query, conn);
try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch (MySqlException e)
{
OnMySqlError(new MySqlErrorEventArgs(e));
conn.Close();
}
}
}
public class Foto
{
public int Id { get; set; }
public int Idcantiere { get; set; }
public DateTime Data { get; set; }
public byte[] Immagine { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment