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();
}
}
它給了我這個錯誤:問題用delete語句
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
全部問題已更新 –