如何使用c#代码删除mdb文件数据而不是修复文件

问题描述:

我有一个mdb文件选择数据假设sa14.mdb我想要相同的mdb文件重命名sa15.mdb但是只有tabale结构我想要sa15中的数据如何使用c#windowformapplication代码在sa14中不是固定类型的posibale。 mdb我选择任何mdb

i have one mdb file select with data suppose sa14.mdb i want same mdb file with rename sa15.mdb but only tabale structure i dint want data in sa15 how it is posibale using c# windowformapplication code is not fixed type in sa14.mdb i select any mdb

您好sandipthummar313

请尝试使用以下代码:

Hi sandipthummar313
Try use following code:
string pathToFile = Server.MapPath("~/path_to_your_file/your_file.mdb");
if (System.IO.File.Exists(pathToFile))
{
  System.IO.File.Delete(pathToFile);
}


获取所有非系统表名称:

Get all the non-system table names:
SELECT MSysObjects.Name AS table_name FROM MSysObjects



然后遍历每个表,删除所有行:


Then loop through each table, removing all the rows:

DELETE * FROM MyTable 

将会这样做。

该文件可能会受益于之后的压缩。

will do it.
The file will probably benefit from compacting afterwards.


我不想删除文件先生我希望数据库表数据删除我选择的任何数据
i din't want file delete sir i want database table data delete any data i select