I'm trying to insert my bitmap Image into MySQL but the problem is that bitmap is not supported. My error:"System.NotSupportedException: 'Parameter type Bitmap is not supported; see https://fl.vu/mysql-param-type. Value: System.Drawing.Bitmap'". My picture datatype in MySQL is a blob. I wonder if I should change the datatype?
My button Register
private void buttonRegister_Click(object sender, EventArgs e)
{
String email = textBoxEmail.Text;
String username = textBoxUsername.Text;
String password = textBoxPassword.Text;
String reTypepassword = textBoxReTypePassword.Text;
UsersClass user = new UsersClass();
System.Security.Cryptography.AesCryptoServiceProvider keyMaker = new System.Security.Cryptography.AesCryptoServiceProvider();
keyMaker.KeySize = 128;
keyMaker.BlockSize = 128;
keyMaker.GenerateKey();
byte[] build = keyMaker.Key;
String Key = Convert.ToBase64String(build);
//MessageBox.Show(Key);
string encryptPassword = user.EncryptString(Key, textBoxPassword.Text);
char[] v = encryptPassword.ToCharArray();
int c = 0;
Bitmap bm = new Bitmap(Image);
for (int w = 0; w < bm.Width; w++)
{
for (int h = 0; h < bm.Height; h++)
{
if (v.Length > c)
{
Color pixel = bm.GetPixel(w, h);
bm.SetPixel(w, h, Color.FromArgb(pixel.R, pixel.G, Convert.ToInt32(v[c])));
c++;
}
}
}
Color p = bm.GetPixel(Image.Width - 1, Image.Height - 1);
bm.SetPixel(Image.Width - 1, Image.Height - 1, Color.FromArgb(p.R, p.G, Convert.ToInt32(c)));
Image = (Image)bm;
imageBox.Image = Image;
myconn.openConnection();
if (password == reTypepassword)
{
MySqlCommand cmd = new MySqlCommand("insert into customer values(@id, @username, @email, @password, @Customer_Request,@location,@address,@key, @picture)", myconn.getConnection());
cmd.Parameters.Add(new MySqlParameter("@id", 0));
cmd.Parameters.Add(new MySqlParameter("@username", textBoxUsername.Text));
cmd.Parameters.Add(new MySqlParameter("@email", textBoxEmail.Text));
cmd.Parameters.Add(new MySqlParameter("@password", encryptPassword));
cmd.Parameters.Add(new MySqlParameter("@Customer_Request", ""));
cmd.Parameters.Add(new MySqlParameter("@location", ""));
cmd.Parameters.Add(new MySqlParameter("@address", textBoxAddress.Text));
cmd.Parameters.Add(new MySqlParameter("@key", Key));
cmd.Parameters.Add(new MySqlParameter("@picture", Image));
cmd.ExecuteNonQuery();
MessageBox.Show("Success to insert");
}
else
{
MessageBox.Show("Please enter the correct password");
}
}