Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SQL Server 2016在VS中插入值时遇到麻烦_Sql_Sql Server 2016 - Fatal编程技术网

使用SQL Server 2016在VS中插入值时遇到麻烦

使用SQL Server 2016在VS中插入值时遇到麻烦,sql,sql-server-2016,Sql,Sql Server 2016,我正在做一个项目,使用VS 2017将图像插入SQL Server 2016,我跟随一些论坛从VS插入数据值。当我执行我的应用程序时,它会导致一个问题 以下是截图: 这是我的密码: public partial class Form1 : Form { SqlConnection CN = new SqlConnection("Data Source=.;Initial Catalog=MyInventory;Integrated Security=True");

我正在做一个项目,使用VS 2017将图像插入SQL Server 2016,我跟随一些论坛从VS插入数据值。当我执行我的应用程序时,它会导致一个问题

以下是截图:

这是我的密码:

public partial class Form1 : Form
{
    SqlConnection CN = new SqlConnection("Data Source=.;Initial 
    Catalog=MyInventory;Integrated Security=True");

    public Form1()
    {
        InitializeComponent();
    }

    private void butSave_Click(object sender, EventArgs e)
    {
        CN.Open();
        int i = 0;

        SqlCommand CMD = new SqlCommand("INSERT INTO  MyInventory (ID, Nombre, Aula, Departamento, Especificacion) VALUES ('" + 
        txtID.Text+ "','" + txtNombre.Text + "','" + txtAula.Text + "','" + 
        txtDep.Text + "',@Especificacion)",CN);

        MemoryStream STREAM = new MemoryStream();
        PB.Image.Save(STREAM, System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[ ] PIC = STREAM.ToArray();

        CMD.Parameters.AddWithValue("@Especificacion", PIC);

        i = CMD.ExecuteNonQuery();

        if (1 > 0)
        {
            MessageBox.Show("Equipo registrado" + i);
        }

        CN.Close();
    }

    private void butOpenPic_Click(object sender, EventArgs e)
    {
        OFD.Filter = "JPG | *.jpg";
        DialogResult RES = OFD.ShowDialog();

        if (RES == DialogResult.OK)
        {
            PB.Image = Image.FromFile(OFD.FileName);
        }
    }
}
很抱歉,没有在SQL Server 2016上上载我的表的图像:


如果不知道您的模式,很难确定,但听起来您好像在试图向ID字段中插入一个值,该值不应提供,因为它将自动生成。所以删除ID及其对应的值。-您不应该将SQL语句连接在一起—使用参数化查询来避免SQL注入—另外,从错误消息中可以看出,您似乎正在尝试将标识值插入表中—不要这样做!不要为定义为
int identity
的列提供值-SQL Server将自动提供自己的值。啊,thnx bro我解决了它