I am using a .mdf database in Visual Studio 2010. When I add information to my table I get error. I don't get any problem when I add the first four rows. But when I add the fifth row I get error.
Here is the error:
SqlException was unhandled
What can the problem be?
dataAccess.AddQuestion("Category1", "Question1?", "1");
dataAccess.AddQuestion("Category2", "Question2?", "2");
dataAccess.AddQuestion("Category3", "Question3?", "3");
dataAccess.AddQuestion("Category4", "Question4?", "4");
dataAccess.AddQuestion("Category5", "Question5?", "5");
I get the error when I add the question number five.
Here is the method for how I add the information to the table in the database.
public void AddQuestion(string title, string question, string answer)
{
sqlConnection = new SqlConnection(connectionString);
sqlCommand = new SqlCommand("INSERT INTO QuestionTable VALUES(@Title, @Question, @Answer)", sqlConnection);
try
{
sqlConnection.Open();
sqlCommand.Parameters.Add(new SqlParameter("@Title", title));
sqlCommand.Parameters.Add(new SqlParameter("@Question", question));
sqlCommand.Parameters.Add(new SqlParameter("@Answer", answer));
sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
}
catch (Exception ex)
{
throw(ex);
}
}
sqlCommandobject.catch (Exception ex)