问题描述
大家好,
每当我尝试将数据插入Access db时,通过我的语法错误异常,我尝试了一切,但仍然出现错误
我尝试过:
插入代码:
cmd = new OleDbCommand(插入RegistrationForm(ClientCount,Name,Address,Muddat,Money_Return_date,Account_status,Taking_Amout,Interest_per_month,Pending_interest_month,Pending_interst_Amount,Total_Amount,Client_image,Document_image1,Document_image2)值(+ lblcount) .Text +','+ textBox20.Text +','+ textBox21.Text +','+ textBox19.Text +','+ textBox18.Text +','+ maskedTextBox1 .Text.ToString()+','+ textBox22.Text +','+ maskedTextBox2.Text.ToString()+','+ textBox23.Text +','+ textBox17.Text +','+ textBox16.Text +','+ textBox15.Text +','+ Convert.ToDouble(textBox13.Text)+','+ Convert.T oDouble(textBox14.Text)+',@ pictureBox6,@ pictureBox4,@ pictureBox5)',con);
conv_photo();
con.Open() ;
int n = cmd.ExecuteNonQuery(); - 这条线上的例外
con.Close();
if(n> 0)
{
MessageBox.Show(记录已插入);
loaddata();
rno ++;
}
else
MessageBox.Show(插入失败);
conv_photo方法:
public void conv_photo()
{
//将照片转换为二进制数据
if(pictureBox6.Image!= null)
{
//使用MemoryStream:
ms = new MemoryStream();
pictureBox6.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
byte [] photo_aray = new byte [ms。长度];
ms.Position = 0;
ms.Read(photo_aray,0,photo_aray.Length);
cmd.Parameters.AddWithValue(@ pictureBox6,photo_aray);
}
if(pictureBox4.Image!= null)
{
//使用MemoryStream:
ms = new MemoryStream();
pictureBox4.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
byte [] photo_aray = new byte [ms .Length];
ms.Position = 0;
ms.Read(photo_aray,0,photo_aray.Length);
cmd.Parameters .AddWithValue(@ pictureBox4,photo_aray);
}
if(pictureBox5.Image!= null)
{
//使用MemoryStream:
ms = new MemoryStream();
pictureBox5.Image.Save(ms,System.Drawing.I maging.ImageFormat.Jpeg);
byte [] photo_aray = new byte [ms.Length];
ms.Position = 0;
ms.Read(photo_aray,0,photo_aray.Length);
cmd.Parameters.AddWithValue(@ pictureBox5,photo_aray);
}
}
输出为:
'2','Atul','india', '4589787978', '收集', '2015年12月5日', '4', '2015年12月6日', '有效', '5000', '500', '5', '2500','7500 ',@ pictureBox6,@ pictureBox4,@ pictureBox5''。
hi all,
Whenever i try to insert data into Access db its through me syntax error exception, i tried everything but still error is coming
What I have tried:
Insert code:
cmd = new OleDbCommand("insert into RegistrationForm(ClientCount,Name,Address,Contact,Documents,Money_Taking_Date,Muddat,Money_Return_date,Account_status,Taking_Amout,Interest_per_month,Pending_interest_month,Pending_interst_Amount,Total_Amount,Client_image,Document_image1,Document_image2) values(" + lblcount.Text + "','" + textBox20.Text + "','" + textBox21.Text + "','" + textBox19.Text + "','" + textBox18.Text + "','" + maskedTextBox1.Text.ToString() + "','" + textBox22.Text + "','" + maskedTextBox2.Text.ToString() + "','" + textBox23.Text + "','" + textBox17.Text + "','" + textBox16.Text + "','" + textBox15.Text + "','" + Convert.ToDouble(textBox13.Text) + "','" + Convert.ToDouble(textBox14.Text) + "',@pictureBox6,@pictureBox4,@pictureBox5)'", con);
conv_photo();
con.Open();
int n = cmd.ExecuteNonQuery(); -- exception coming on this line
con.Close();
if (n > 0)
{
MessageBox.Show("record inserted");
loaddata();
rno++;
}
else
MessageBox.Show("insertion failed");
conv_photo method:
public void conv_photo()
{
//converting photo to binary data
if (pictureBox6.Image != null)
{
//using MemoryStream:
ms = new MemoryStream();
pictureBox6.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd.Parameters.AddWithValue("@pictureBox6", photo_aray);
}
if (pictureBox4.Image != null)
{
//using MemoryStream:
ms = new MemoryStream();
pictureBox4.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd.Parameters.AddWithValue("@pictureBox4", photo_aray);
}
if (pictureBox5.Image != null)
{
//using MemoryStream:
ms = new MemoryStream();
pictureBox5.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd.Parameters.AddWithValue("@pictureBox5", photo_aray);
}
}
output is :
'2','Atul','india','4589787978','collected','12/05/2015','4','12/06/2015','Active','5000','500','5','2500','7500',@pictureBox6,@pictureBox4,@pictureBox5)'.
推荐答案
这篇关于插入数据时出现语法异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!