我试图解决为什么我的代码无法正常工作.提示是预先准备的.我也想知道,当这个工作时,主键,在这种情况下,ID列也会重置并从1开始全部?
connection = new SqlConnection(connectionString);
connection.Open();
sql = "DELETE * From Guests";
sqlCommand = new SqlCommand(sql, connection);
sqlCommand.EndExecuteNonQuery();
connection.Close();
Run Code Online (Sandbox Code Playgroud)
你不需要星号
DELETE FROM Guests
Run Code Online (Sandbox Code Playgroud)
要重置主键,请使用
TRUNCATE TABLE Guests
Run Code Online (Sandbox Code Playgroud)
你想要的
sqlCommand.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
不 EndExecuteNonQuery