I am trying to create an INSERT INTO
query, that which creates a value in a table with the value null; however, this is not working.
This is the code:
cmd = new SqlCommand("INSERT INTO Questions ([Student_ID],[Teacher_ID],[Question],[Answer],[Answered]) VALUES (@Student_ID,@Teacher_ID,@Question,@Answer,@Answered)", con);
cmd.Parameters.AddWithValue("@Student_ID", FrmLogIn.User_ID);
cmd.Parameters.AddWithValue("@Teacher_ID", cmboxTeacherChoice.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@Question", tbStudentQuestion.Text);
cmd.Parameters.AddWithValue("@Answer", null);
cmd.Parameters.AddWithValue("@Answered", 0);
This code works when a value is put in cmd.Parameters.AddWithValue("@Answer", null);
instead of null being there, but I need this value to be null. In the database this variable is saved as a nvarchar(MAX)
and is allowed nulls, am I doing something incorrect? Please let me know.
Any answers are appreciated, if I was unclear please inform me, thank you.