Look at your code:
cmd = new SqlCommand("insert into Answer values(@que_id,@stu_id,@ans)", con);
Now, well done for using parameterized queries, but...look at your table definition:
"i have table answer with colums as answer_id primary key,student_id foreign key,question_id foreign key,student_answer varchar(400)"So your table is:
answer_id INT, primary key, probably IDENTITY
student_id INT, foreign key
question_id INT, foreign key
student_answer varchar(400)
But...you don;t tell SQL which columns to INSERT values into. So it starts with the first column, and move up through the table. Since you only set three values, It decides the first three parameters are INT values, and tries to convert them as such - but the third isn't so it fails.
It is good practice to always list the columns you want to INSERT:
cmd = new SqlCommand("INSERT INTO Answer (question_id, student_id, student_answer) VALUES (@que_id,@stu_id,@ans)", con);
Which will solve your problem.
[edit]Matched up columns with parameters :doh: - OriginalGriff[/edit]