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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -