c# - Error : Conversion failed when converting date and/or time from character string -
in sql table date_of_birth
, date_of_joining
data type date
. need perform update
.
i have code , it's showing error - conversion failed when converting date and/or time character string.
please help.
string sql = "update employees set designation = '" +textbox_beupdtd.text + "', employee_subgroup = '" +combobox_beupdt.text + "', date_of_birth = " + datetimepicker_dobupdt.text + ", date_of_joining = " + datetimepicker_dojupdt.text + " employee_name ='"+combobox_empnm.text+"' "; sqlcommand cmd7 = new sqlcommand(, con7); con7.open(); int o = cmd7.executenonquery(); messagebox.show(o +" : record has been updated"); '
aside sql injection issues sending in user variables directly database, suggest using parameterized queries simplify you're trying do.
sqlcommand cmd7 = new sqlcommand("update employees set designation = @designation, employee_subgroup = @subgroup, date_of_birth = @dateofbirth, date_of_joining = @dateofjoining employee_name = @employeename", con7); cmd7.parameters.addwithvalue("designation", textbox_beupdtd.text); cmd7.parameters.addwithvalue("subgroup", combobox_beupdt.text); cmd7.parameters.addwithvalue("dateofbirth", datetimepicker_dobupdt.value.date); cmd7.parameters.addwithvalue("dateofjoining", datetimepicker_dojupdt.value.date); cmd7.parameters.addwithvalue("employeename",combobox_empnm.text); con7.open(); int o = cmd7.executenonquery(); messagebox.show(o +" : record has been updated")
that said, there issues database schema. suggest not key on employee name, as: a) it's not unique, b) may mistyped in form it's pure text box, c) may change on time (eg. marriage, etc.)
Comments
Post a Comment