C# SQL Server command data type mismatch -
i want insert record student table , used sqlcommand
when executing command shown here, datatype mismatch error occurs.
system.data.sqlclient.sqlcommand cmd = new system.data.sqlclient.sqlcommand("insert student(studentid,studentname,birthdate) values(" + studentid.text + ",'" + studentname.text +"','" + birthdate.text + "')", con);
you can use parameters solve problem this:
sqlcommand cmd = new sqlcommand("insert student(studentid, studentname, birthdate) values(@studentid, @studentname, @birthdate)" , con); cmd.parameters.addwithvalue("@studentid", studentid.text); cmd.parameters.addwithvalue("@studentname", studentname.text); cmd.parameters.addwithvalue("@birthdate", birthdate.text); cmd.executenonquery();
Comments
Post a Comment