logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Błąd przy wgrywaniu zdjęcia Avatar do LongBlob w MySQL

silentyt 06 Kwi 2019 10:25 471 2
REKLAMA
  • #1 17888819
    silentyt
    Poziom 5  
    Posty: 587
    Pomógł: 4
    Ocena: 42
    Witam,
    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 97

    Za 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!
  • REKLAMA
  • #2 17888968
    Dotnetvb
    Poziom 18  
    Posty: 309
    Pomógł: 23
    Ocena: 19
    Jeśli już to update tabela set pole=@_pole Where id=@_id;
  • #3 17889004
    Dżyszla
    Poziom 42  
    Posty: 7075
    Pomógł: 1095
    Ocena: 225
    Składnia jest niepoprawna - ni to INSERT ni to UPDATE. Albo INSERT INTO tabela (pola, ...) VALUES (wartości, ...), albo UPDATE tabela SET pole = wartosc WHERE pole_klucz = wartosc_klucz
REKLAMA