2015-11-05 41 views
-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; 

現在在形式的添加按鈕以保存數據和上面的按鈕的代碼:

+2

您的代碼很容易受到SQL注入。使用類似實體框架的ORM或使用命令參數。 – Dai

+0

你準確得到了什麼錯誤? – auburg

+5

另外,你看到的'NotImplementedException'的堆棧跟蹤是什麼?你還沒有指定哪個代碼導致異常被拋出。 – Dai

回答

0

「的方法,或操作未實現」是的默認消息,它通常在一個特點,就是尚未得到執行的代碼明確拋出。

很多自動生成的代碼使用此異常,以指示你應該把自己的代碼的地方。例如。當我使用Visual Studio來自動實現接口的方法,會產生這樣的:

bool IMyInterface.MyMethod(string parameter) 
{ 
    throw new NotImplementedException(); 
} 

方法的簽名是不是我做的,因爲它可以自動推斷,但我將不得不提供方法的主體。
所以,看看你的異常的堆棧跟蹤,找出你的應用程序需要,你還沒有編寫的代碼。


除此之外,SQL生成的代碼是一個可怕的,錯誤的和不可維護的混亂。有很多知識在線(主要在堆棧溢出:))如何得到它的權利 - 使用它。

相關問題