Get error while trying to insert data in an access database with c#

0

Visual Studio gives me the follow error while trying to save data into my access database:

OleDBException(0x80040E14): syntax error in INSERT INTO command

I get the error after clicking my save button ('btnFolieSpeichern').

In my database table "Folien" 'Hersteller', 'Serie' and 'Farbe' are strings, 'EK-Preis' is a double and 'Bild' is an OLE-Object.

Here is my code:

private void btnFolieSpeichern_Click(object sender, EventArgs e)
{
    try
    {
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "INSERT INTO Folien (Hersteller,Serie,Farbe,EK-Preis,Bild) VALUES ('" + tbFolieHersteller.Text + "','" + tbFolieSerie.Text + "','" + tbFolieFarbe.Text + "','" + tbFolieEKPreis.Text + "',@folienbild)";

        //converting photo to binary data
        if (pbFolieBildHinzufügen.Image != null)
        {
            MemoryStream ms = new MemoryStream();
            pbFolieBildHinzufügen.Image.Save(ms, ImageFormat.Jpeg);
            byte[] photo_aray = new byte[ms.Length];
            ms.Position = 0;
            ms.Read(photo_aray, 0, photo_aray.Length);
            command.Parameters.AddWithValue("@folienbild", photo_aray);
        }

        command.ExecuteNonQuery();
        MessageBox.Show("Folie erfolgreich hinzugefügt!", "Erfolgreich!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        connection.Close();

        tbFolieHersteller.Text = "";
        tbFolieSerie.Text = "";
        tbFolieFarbe.Text = "";
        tbFolieEKPreis.Text = "";
        pbFolieBildHinzufügen.Image = null;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error " + ex);
    }
}

The code for loading the picture:

private void btnBildLaden_Click(object sender, EventArgs e)
{
    openFileDialog3.Filter = "jpeg|*.jpg|png|*.png|bmp|*.bmp|all files|*.*";
    DialogResult res = openFileDialog3.ShowDialog();
    if (res == DialogResult.OK)
    {
        pbFolieBildHinzufügen.Image = Image.FromFile(openFileDialog3.FileName);
    }
}

Error message:

enter image description here

I tried filling tbFolieEKPreis with '55', '55.0' and '55,0'.

Thank you for your help!!!

c#
mysql
database
insert
memorystream
asked on Stack Overflow Mar 11, 2017 by D. Jung • edited Mar 11, 2017 by csharpbd

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0