嗨,我正在尝试使用 c# 和 SQL Server 2008 数据库更新表中的图像,但出现错误(路径不能为空。参数名称:路径)你能帮帮我吗
这是代码:
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);
}
}