c# - Overflow Error on inserting data on Access database -
c# - Overflow Error on inserting data on Access database -
private void button1_click(object sender, eventargs e) { seek { connections.con.open(); string str = "insert `employee` (`firstname`, `lastname`, `age`, `contactnumber`, `username`, `password`) values (?, ?, ?, ?, ?, ?)"; oledbcommand cmd = new oledbcommand(str, connections.con); cmd.parameters.addwithvalue("@?", txtfirst.text.tostring()); cmd.parameters.addwithvalue("@?", txtlast.text.tostring()); cmd.parameters.addwithvalue("@?", txtage.text.tostring()); cmd.parameters.addwithvalue("@?", txtcon.text.tostring()); cmd.parameters.addwithvalue("@?", txtuser.text.tostring()); cmd.parameters.addwithvalue("@?", txtpass.text.tostring()); cmd.executenonquery(); messagebox.show("registration successful"); } grab (exception ex) { messagebox.show("error" + ex); } { connections.con.close(); this.dispose(); this.close(); f1.show(); } }
this code should save first name lastly name age contact number username , password user come in problem overflow exception error pops whenever click button.. please help i've been searching everywhere solve problem can't find answer
the addwithvalue method creates parameter datatype equal value passed. pass strings parameter created datatype string. not work when seek insert value in numeric field.
change code
cmd.parameters.addwithvalue("@?", txtfirst.text); cmd.parameters.addwithvalue("@?", txtlast.text); cmd.parameters.addwithvalue("@?", convert.toint32(txtage.text)); cmd.parameters.addwithvalue("@?", convert.toint32(txtcon.text)); cmd.parameters.addwithvalue("@?", txtuser.text); cmd.parameters.addwithvalue("@?", txtpass.text);
as sec guess, contact number field of type numeric long. access allow number of kind @ maximum 2147483647.
in context possible have telephone number when interpreted numeric value bigger limit. consequence overflow error.
i suggest utilize string contact number plenty chars accomodate more 1 telephone number (30 chars)
as side note. store birth date , not age otherwise next year have problem.
c# database ms-access
Comments
Post a Comment