本文介绍了将图像插入数据库错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像插入数据库,但是我收到错误附加信息:@images附近的语法错误。













< pre lang =c#>使用系统; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Data.SqlClient;
使用System.IO;
命名空间Carprogram
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

SqlConnection connection = new SqlConnection(Data Source = NAWAF; Initial Catalog = CAR; Integrated Security = True);
string imgloc =;
SqlCommand cmd;
private void linkLabel4_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter =png文件(* .png)| * .png | jpg文件(*。jpg)| * .jpg |所有文件(*。*)| *。*;
if(dialog.ShowDialog()== DialogResult.OK)
{
imgloc = dialog.FileName.ToString();
pictureBox1.ImageLocation = imgloc;

}
}


private void groupBox1_Enter(object sender,EventArgs e)
{

}

private void save_Click(object sender,EventArgs e)
{


byte [] images = null;
FileStream Streem = new FileStream(imgloc,FileMode.Open,FileAccess.Read);
BinaryReader brs = new BinaryReader(Streem);
images = brs.ReadBytes((int)Streem.Length);

SqlConnection con = new SqlConnection(Data Source = NAWAF; Initial Catalog = CAR; Integrated Security = True);
con.Open();
SqlCommand cmd = new SqlCommand(@INSERT INTO [CAR]。[dbo]。[vehicleinfo]
([modely]
,[make]
,[model]
,[颜色]
,[类型]
,[里程表]
,[vin]
,[车辆]
,[driverop]
,[部门]
,[img])

VALUES
('+ modely.Text +','+ make.Text +',' + model.Text +','+ color.Text +','+ type.Text +''+ odometer.Text +','+ vin.Text +','+ vehicle.Text +','+ driverop.Text +','+ department.Text +',@ images,con);


cmd.Parameters。添加(@ images,图像);
cmd.ExecuteNonQuery();

con.Close();









}


}
}





什么我试过了:



 cmd.Parameters。 add  new  SqlParameter   @ images ,images); 
解决方案


这篇关于将图像插入数据库错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:22
查看更多