-2
我有添加按鈕形式,只要我點擊它,我得到這個錯誤信息 這裏是添加按鈕VS2010的方法或操作未實現
private void btnajoutemploye_Click(object sender, EventArgs e)
{
EmployeControlleur ec = new EmployeControlleur();
EmployeInfo ei = new EmployeInfo();
bool result;
ei.matricule = int.Parse(mat.Text);
ei.nom = nom.Text;
ei.prenom = pre.Text;
ei.naissance = naiss.Text;
ei.lieu = lieu.Text;
ei.sexe = sex.Text;
ei.situationfamille = stmat.Text;
result = ec.ajoutemploye(ei);
if (result == true)
{
MessageBox.Show("Opération effectuée avec succès...");
this.Close();
}
else
{
MessageBox.Show("Erreur...");
}
和代碼代碼的方法
class EmployeControlleur
{
public bool ajoutemploye(EmployeInfo employe)
{
DataBaseHelper dh = new DataBaseHelper();
dh.ExecuteNonQuery("Insert into Employe values (" + employe.matricule + ",'" + employe.nom + ",'" + employe.prenom + ",'"
+ employe.naissance + ",'" + employe.lieu + ",'" + employe.sexe + ",'" + employe.situationfamille + ",'"
+ employe.personnecontact + ")");
return true;
}
}
有人可以幫助我看得更清楚嗎?
予解釋: 我創建Employee類的信息和所用ExecuteReader方法,其在這裏是代碼:
class EmployeInfo
{
private int Matricule;
public int matricule
{
get { return Matricule; }
set { Matricule = value; }
}
private string Nom;
public string nom
{
get { return Nom; }
set { Nom = value; }
}
private string Prenom;
public string prenom
{
get { return Prenom; }
set { Prenom = value; }
}
private string Date_naiss;
public string naissance
{
get { return Date_naiss; }
set { Date_naiss = value; }
}
private string lieu_naiss;
public string lieu
{
get { return lieu_naiss; }
set { lieu_naiss = value; }
}
private string Sexe;
public string sexe
{
get { return Sexe; }
set { Sexe = value; }
}
private string Situation_fam;
public string situationfamille
{
get { return Situation_fam; }
set { Situation_fam = value; }
}
private string Personnecontact;
public string personnecontact
{
get { return Personnecontact; }
set { Personnecontact = value; }
}
private int id_serv;
public int idserv
{
get { return id_serv; }
set { id_serv = value; }
}
private int id_statut;
public int idstatut
{
get { return id_statut; }
set { id_statut = value; }
}
public EmployeInfo()
{
}
public EmployeInfo(int employe)
{
DataBaseHelper dh = new DataBaseHelper();
SqlDataReader dr;
dr = dh.ExecuteReader("Select * from Employe where Matricule = "+employe);
if (dr.Read())
{
matricule=dr.GetInt32(Matricule);
nom=dr["Nom"].ToString();
prenom=dr["Prenom"].ToString();
naissance=dr["Date_naiss"].ToString();
lieu=dr["Lieu_naiss"].ToString();
sexe=dr["Sexe"].ToString();
situationfamille=dr["Situation_fam"].ToString();
personnecontact=dr["Personnecontact"].ToString();
idserv=dr.GetInt32(id_serv);
idstatut=dr.GetInt32(id_statut);
}
dr.Close();
}
}
第二類Employee控制器,代碼:
public bool ajoutemploye(EmployeInfo employe)
{
DataBaseHelper dh = new DataBaseHelper();
dh.ExecuteNonQuery("Insert into Employe values (" + employe.matricule + ",'" + employe.nom + ",'" + employe.prenom + ",'"
+ employe.naissance + ",'" + employe.lieu + ",'" + employe.sexe + ",'" + employe.situationfamille + ",'"
+ employe.personnecontact + ")");
return true;
現在在形式的添加按鈕以保存數據和上面的按鈕的代碼:
您的代碼很容易受到SQL注入。使用類似實體框架的ORM或使用命令參數。 – Dai
你準確得到了什麼錯誤? – auburg
另外,你看到的'NotImplementedException'的堆棧跟蹤是什麼?你還沒有指定哪個代碼導致異常被拋出。 – Dai