public static void DeleteThreads(int threadID)
{
StringBuilder sb = new StringBuilder();
sb.Append("DELETE FROM dbo.Threads");
sb.Append(" WHERE [email protected]");
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 [email protected]");
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();
}
}
どのDBMSを使用していますか? –
"dbo.Threads"と "WHERE"の間に空白がありませんか? – Jacob
すべて質問が更新されました –