public static void DeleteThreads(int threadID)
{
StringBuilder sb = new StringBuilder();
sb.Append("DELETE FROM dbo.Threads");
sb.Append(" WHERE ThreadsID=@ThreadsID");
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection myConnection = new SqlConnection(myConnectionString))
{
myConnection.Open();
SqlCommand sqlCommand = new SqlCommand(sb.ToString(), myConnection);
sqlCommand.Parameters.Add("@ThreadsID", SqlDbType.Int);
sqlCommand.Parameters["@ThreadsID"].Value = threadID;
sqlCommand.ExecuteNonQuery();
}
}
Это дает мне эту ошибку:
The DELETE statement conflicted with the REFERENCE constraint "FK_Comments_Threads". The conflict occurred in database "model", table "dbo.Comments", column 'ThreadsID'.
Оператор был прекращен.
Если это исправить эту ошибку:
enter code here public static void DeleteComments(int threadID)
{
StringBuilder sb = new StringBuilder();
sb.Append("DELETE FROM dbo.Comments");
sb.Append(" WHERE ThreadsID=@ThreadsID");
string myConnectionString = AllQuestionsPresented.connectionString;
using (SqlConnection myConnection = new SqlConnection(myConnectionString))
{
myConnection.Open();
SqlCommand sqlCommand = new SqlCommand(sb.ToString(), myConnection);
sqlCommand.Parameters.Add("@ThreadsID", SqlDbType.Int);
sqlCommand.Parameters["@ThreadsID"].Value = threadID;
sqlCommand.ExecuteNonQuery();
}
}