利用MySQL中的Parameters.Add方法,将byte[]添加为MediumBlob类型的数据到数据库。
using MySql.Data.MySqlClient;
using System;using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SaveGetImageMySql
{
class Demo
{
private static byte[] FileToBytes(string filePath)
{
FileInfo fi = new FileInfo(filePath);
byte[] buffer = new byte[fi.Length];
FileStream fs = fi.OpenRead();
fs.Read(buffer, 0, Convert.ToInt32(fi.Length));
fs.Close();
return buffer;
}
private static void CreateFile(byte[] fileBuffer,string newFilePath)
{
if (File.Exists(newFilePath))
{