如何:刪除資料庫 (以程式設計的方式)

在此主題中,您將了解如何刪除 SQL Server Compact 4.0 資料庫。因為 SQL Server Compact 4.0 資料庫是檔案系統中的檔案,刪除檔案即可刪除 SQL Server Compact 資料庫。

SQL Server Compact 4.0 的程序

若要刪除資料庫

  • 呼叫 System.IO.File.Delete 方法,並傳遞 SQL Server Compact 資料庫的路徑和檔名。

    File.Delete("Test.sdf");
    

範例

此範例會刪除名為 Test.sdf 的現有 SQL Server Compact 資料庫。

using System.IO;

namespace MySQLCEApplication
{
    class Program
    {
        static void Main(string[] args)
        {
         // Call the File class Delete method to delete the database.
            File.Delete("Test.sdf");
        }
    }
}
Imports System.IO

Module Module1

    Sub Main()
        'Call the File class Delete method to delete the database.
        File.Delete("Test.sdf")

    End Sub

End Module

請參閱

其他資源

使用資料庫 (SQL Server Compact)