Witam,
Otóż gdy próbuje wgrać "Avatar" użytkownika do bazy MySQL na LongBlob to dostaje taki dziwny błąd:
Za cholerę nie wiem o co z nim chodzi... Próbowałem już chyba wszyskiego!
Kod:
Dodam, że podobny kod mam w innym form i wszystko działa!
Z góry dziękuje za pomoc!
Otóż gdy próbuje wgrać "Avatar" użytkownika do bazy MySQL na LongBlob to dostaje taki dziwny błąd:
Spoiler:
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'avatar WHERE UserName = 'hesa656' Values(_binary '‰PNG
\0\0\0
IHDR\0\0 \0\' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at SoundShadow.profile.pictureBox1_Click(Object sender, EventArgs e) in C:\Users\Robert\source\repos\SoundShadow\SoundShadow\profile.cs:line 97Za cholerę nie wiem o co z nim chodzi... Próbowałem już chyba wszyskiego!
Kod:
Spoiler:
try
{
OpenFileDialog openFileDialog1 = new OpenFileDialog(); //wybierz avatar
openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
avatar.Image = Image.FromFile(openFileDialog1.FileName);
if (avatar.Image.Width == 800 && avatar.Image.Height == 800)
{
FileStream Stream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); //przekonwertuj na binary
BinaryReader brs = new BinaryReader(Stream);
images = brs.ReadBytes((int)Stream.Length);
try
{
String insertQuery = "INSERT INTO logindata avatar WHERE UserName = '" + logindata.userNick + "' Values(@img)"; //wgraj avatar
connectionstring.Open();
command = new MySqlCommand(insertQuery, connectionstring);
command.Parameters.Add("@img", MySqlDbType.LongBlob);
command.Parameters["@img"].Value = images;
avatar.Image = Image.FromFile(openFileDialog1.FileName);
if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("Pomyślnie wgrano avatar!");
}
connectionstring.Close();
}catch (Exception exe)
{
MessageBox.Show(exe.ToString());
Clipboard.SetText(exe.ToString());
}
}
else
{
MessageBox.Show("Obraz ma złe wymiary!");
}
}
} catch
{
}Dodam, że podobny kod mam w innym form i wszystko działa!
Z góry dziękuje za pomoc!