C# 尝试使用c在access数据库中插入数据时出错#
Visual Studio在尝试将数据保存到access数据库时出现以下错误: OLEDBEException(0x80040E14):INSERT INTO命令中的语法错误 单击“保存”按钮(“btnfoliespeichen”)后出现错误 在我的数据库表“Folien”中,“Hersteller”、“Serie”和“Farbe”是字符串,“EK Preis”是双精度的,“Bild”是OLE对象 这是我的密码:C# 尝试使用c在access数据库中插入数据时出错#,c#,mysql,database,insert,memorystream,C#,Mysql,Database,Insert,Memorystream,Visual Studio在尝试将数据保存到access数据库时出现以下错误: OLEDBEException(0x80040E14):INSERT INTO命令中的语法错误 单击“保存”按钮(“btnfoliespeichen”)后出现错误 在我的数据库表“Folien”中,“Hersteller”、“Serie”和“Farbe”是字符串,“EK Preis”是双精度的,“Bild”是OLE对象 这是我的密码: private void btnFolieSpeichern_Click(obje
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);
}
}
加载图片的代码:
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);
}
}
错误消息:
我试着用'55'、'55.0'和'55,0'填充tbFolieEKPreis
谢谢你的帮助 使用括号
[EK Preis]
在哪里@juergendEK Preis
包含特殊字符。用括号括住那个列名来转义Itah明白了,谢谢,工作得很好!您的代码易受SQL注入攻击