c# - Error: Number of query values and destination fields are not the same - what am I doing wrong? -


i looking solutions error, nothing solve problems. have many items values in following sql code. don't know doing wrong?

my access data base has following columns (eveything "short text" except , id obviously)

  • id
  • email
  • kennwort
  • vorname
  • nachname
  • telefonnummer
  • strasse
  • pls
  • ort
  • aktivierungscode

edit: took column had date out couldn't figure out how implement sql code... still, same error. added parameters suggested.

code:

public class webuser  {  private string _vorname; private string _nachname; private string _email; private string _kennwort;  private string _strasse; private string _plz; private string _ort; private string _telefonnummer; private string _aktivierungscode;   public webuser() {     //     // todo: add constructor logic here     // }  public string email {     { return _email; }     set { _email= value; } }  public string kennwort {     {return kennwort; }     set { _kennwort = value; } }  public string vorname {     { return _vorname; }     set { _vorname = value; } }  public string nachname {     { return _nachname; }     set { _nachname = value; } }   public string strasse {     { return _strasse; }     set { _strasse = value; } }  public string plz {     { return _plz; }     set { _plz = value; } }  public string ort {     { return _ort; }     set { _ort = value; } }  public string telefonnummer {     { return _telefonnummer; }     set { _telefonnummer = value; } }   public string aktivierungscode {     { return _aktivierungscode; }     set { _aktivierungscode = value; } }  public bool checkuser(string email) {     string sql = "select email, kennwort benutzerdatenbank email ='" + email + "'";     string constr = "provider=microsoft.ace.oledb.12.0;data source=" + system.web.httpcontext.current.server.mappath("~/app_data/benutzerdatenbank.accdb");      oledbconnection con = new oledbconnection(constr);     con.open();     oledbdataadapter da = new oledbdataadapter(sql, con);     dataset ds = new dataset();     da.fill(ds);     con.close();      if (ds.tables[0].rows.count == 1)         return true;     else         return false; }  public bool adduser(string email, string kennwort) {     //hinzufügen eines neuen benutzers in der tabelle 'tbluser'     //ergebniswert: wahr=hinzufügen hat funktioniert     //              falsch=hinzufügen hat nicht funktioniert (email adresse existiert bereits in der db)      //1. prüfen, ob der benutzer bereits in der db existiert; wenn ja => abbruch     if (this.checkuser(email) == true)     {         return false; //email existiert bereits     }     else     {         //datensatz anlegen: email, passwort, enabled, aktivierungscode         //30-stelligen-aktivierungscode erzeugen         string zeichen = "abcdefghijklmnopqrstuvwxyzabcdefghjiklmnopqrstuvwxyz0123456789";         string aktivierungscode = "";         random rnd = new random();         (int = 1; < 62; i++)         {             aktivierungscode = aktivierungscode + zeichen.substring(rnd.next(0, zeichen.length - 1), 1);         }          string sql = "insert benutzerdatenbank (email, kennwort, vorname, nachname, telefonnummer, strasse, plz, ort, aktivierungscode) values ('" +         email + "','" + kennwort + "','" + vorname + "','" + nachname + "','" + telefonnummer + "','" + "','"+ strasse + "','" + plz + "','" + ort + "','" + aktivierungscode + "');";            //benutzer anlegen (datensatz in db anfügen = insert-anweisung ausführen         string constr = "provider=microsoft.ace.oledb.12.0;data source=" + system.web.httpcontext.current.server.mappath("~/app_data/benutzerdatenbank.accdb");         oledbconnection con = new oledbconnection(constr); //neues verbindungsobjekt         oledbcommand cmd = new oledbcommand(sql, con);          con.open();         cmd.executenonquery(); //ausführen einer datenmanipulationsanweisung (insert, update; delete)         con.close();          //versenden des bestätigungslinks (erst später)          return true;     }  }  public void readuser(string email, string kennwort) {     string sql = "select * benutzerdatenbank email='" + email + "' , kennwort ='" + kennwort + "'";     string constr = "provider=microsoft.ace.oledb.12.0;data source=" + system.web.httpcontext.current.server.mappath("~/app_data/benutzerdatenbank.accdb");      oledbconnection con = new oledbconnection(constr);     con.open();     oledbdataadapter da = new oledbdataadapter(sql, con);     dataset ds = new dataset();     da.fill(ds);     con.close();      if (ds.tables[0].rows.count == 1)     {         this.email = (string)ds.tables[0].rows[0]["email"];         this.vorname = (string)ds.tables[0].rows[0]["vorname"];         this.nachname = (string)ds.tables[0].rows[0]["nachname"];         this.strasse = (string)ds.tables[0].rows[0]["strasse"];         this.plz = (string)ds.tables[0].rows[0]["plz"];         this.ort = (string)ds.tables[0].rows[0]["ort"];         this.telefonnummer = (string)ds.tables[0].rows[0]["telefonnummer"];      }     else     {         this.email = "";         this.vorname = "";         this.nachname = "";     } } 

}

you have 10 columns in insert clause , 11 values in values clause.

i think '0' in kennwort + "',0,'" + vorname issue.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -