Created
July 25, 2019 08:52
-
-
Save orlodax/f4450e9d4197aff873431a94c8b2635f to your computer and use it in GitHub Desktop.
Blob SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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