Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 2008 c#_C#_Sql Server 2008_Sql Update - Fatal编程技术网

更新图像sql server 2008 c#

更新图像sql server 2008 c#,c#,sql-server-2008,sql-update,C#,Sql Server 2008,Sql Update,您好,我正在尝试使用c#和SQL server 2008数据库更新表中的图像,但我遇到了一个错误(路径不能为null。参数名称:Path)。您能帮我吗 这是代码: try { byte[] imgData; imgData = File.ReadAllBytes(pictureBox.ImageLocation); string vsql = strin

您好,我正在尝试使用c#和SQL server 2008数据库更新表中的图像,但我遇到了一个错误(路径不能为null。参数名称:Path)。您能帮我吗

这是代码:

            try
            {
                byte[] imgData;
                imgData = File.ReadAllBytes(pictureBox.ImageLocation);
                string vsql = string.Format("SELECT id_cl FROM classe WHERE Nclasse='" + comboBoxcl.Text + "'");
                SqlCommand dra = new SqlCommand(vsql, vCon);
                vCon.Open();
                SqlDataReader dr = dra.ExecuteReader();
                int a = 0;
                while (dr.Read())
                {
                    a = int.Parse(dr["id_cl"].ToString());
                }
                vCon.Close();
                etd = new Etudiant(textBoxN.Text, textBoxP.Text, CNE, textcin.Text, a, textphoto.Text); 
                etd.Modifier_etudiant(D, imgData);
                MessageBox.Show("Modifier", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
//以下是修改功能

     public void Modifier_etudiant(int ID, byte[] image)
    {
        string vsql = string.Format("UPDATE etudiant SET nom = @nom, prenom = @prenom,cne = @cne, cin = @cin, classe = @classe, photo = @photo, image = @DATA WHERE id_etd='"+ID+"'");
        try
        {
            vCon.Open();
            SqlCommand azert = new SqlCommand(vsql, vCon);
            azert.Parameters.Add("@nom", GetNom());
            azert.Parameters.Add("@prenom", GetPernom());
            azert.Parameters.Add("@cne", GetCne());
            azert.Parameters.Add("@cin", GetCin());
            azert.Parameters.Add("@classe", GetClasse());
            azert.Parameters.Add("@photo", GetNomPhoto());
            azert.Parameters.Add("@DATA", image);
            azert.ExecuteNonQuery();
            vCon.Close();
        }catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

这是编译时错误还是运行时错误?同样在你的代码行中
etd.Modifier\u etudiant(D,imgData)什么是
D
?这是申报的吗?打字错误?根据你的错误,它看起来很直截了当。图像的路径为空。。。我将逐步检查您的第一个代码块,看看
pictureBox.ImageLocation
分配给
imgData
.D的是Id--public void修饰符\u etudiant(int Id,byte[]image)。pictureBox.ImageLocation可能为空。你应该检查一下原因您不应该将SQL语句连接在一起,而应该使用参数化查询来避免SQL注入