将图像插入Access表时“插入到语句中的语法错误”

时间:2017-11-21 10:36:34

标签: c# sql winforms ms-access

我正在尝试将文本和图像插入表格中。这是我的代码:

conn.Open();
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "INSERT INTO users (user_name,father_name,phone,email,cnic,address,user_type,workshop,department,designation,emergency_no,image) values(@user_name,@father_name,@phone,@email,@cnic,@address,@user_type,@workshop,@department,@designation,@emergency_no,@image);";
//using MemoryStream:
ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = ms.GetBuffer();

cmd.Parameters.AddWithValue("@user_name", txtUserName.Text);
cmd.Parameters.AddWithValue("@father_name", txtFatherName.Text);
cmd.Parameters.AddWithValue("@phone", txtPhone.Text);
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@cnic", txtCNIC.Text);
cmd.Parameters.AddWithValue("@address", txtAddress.Text);
cmd.Parameters.AddWithValue("@user_type", txtType.Text);
cmd.Parameters.AddWithValue("@workshop", txtWorkshop.Text);
cmd.Parameters.AddWithValue("@department", txtDepartment.Text);
cmd.Parameters.AddWithValue("@designation", txtDesignation.Text);
cmd.Parameters.AddWithValue("@emergency_no", txtEmergency.Text);
cmd.Parameters.AddWithValue("@image", photo_aray);
cmd.ExecuteNonQuery();

问题是每当我使用图像字段时,我都会收到错误

  

插入语句

中的语法错误

如果没有数据插入图像字段,它就像魅力一样。我还制作了错误的屏幕截图。

enter image description here

1 个答案:

答案 0 :(得分:1)

Microsoft Access OLEDB提供程序将<div class="carousel-inner"> <div class="item"> <div class="views-field views-field-field-style-image"> <div class="field-content"> <a href="/mypage"> <video loop autoplay muted playsinline"> <source src="https://example.com/position1.webm" type="video/webm"> <source src="https://example.com/position1.mp4" type="video/mp4"> <source src="https://example.com/position1.ogv" type="video/ogv"> <img alt="" class="img-responsive" data-loaded="true" src="https://example.com/position1.jpg" typeof="foaf:Image"> </video> </a> </div> </div> </div> <div class="item"> <div class="views-field views-field-field-style-image"> <div class="field-content"> <a href="/mypage"> <video loop autoplay muted playsinline"> <source src="https://example.com/position2.webm" type="video/webm"> <source src="https://example.com/position2.mp4" type="video/mp4"> <source src="https://example.com/position2.ogv" type="video/ogv"> <img alt="" class="img-responsive" data-loaded="true" src="https://example.com/position2.jpg" typeof="foaf:Image"> </video> </a> </div> </div> </div> <div class="item"> <div class="views-field views-field-field-style-image"> <div class="field-content"> <a href="/mypage"> <video loop autoplay muted playsinline"> <source src="https://example.com/position3.webm" type="video/webm"> <source src="https://example.com/position3.mp4" type="video/mp4"> <source src="https://example.com/position3.ogv" type="video/ogv"> <img alt="" class="img-responsive" data-loaded="true" src="https://example.com/position3.jpg" typeof="foaf:Image"> </video> </a> </div> </div> </div> </div> 视为Access SQL中的保留字,因此您需要将该列名括在方括号中:

IMAGE