简体   繁体   English

使用 c# 在 Visual Studio 中删除 MSSQL 代码正在运行,但是当我重新启动时它返回到原始状态

[英]MSSQL delete code in visual studio with c# is running, but when I restart it returns to its original state

In my c # project that I work with local db, I need to clear the table.在我使用本地数据库的 c# 项目中,我需要清除表。 I can view the table that I cleared while the program is running, but when I restart it, it returns to its original state.However, I do not experience it problem when adding to my Sql table.i dont understand.Is there anyone who can help me?程序运行时可以查看清空的表,重启后又恢复原状可以帮我?

 SqlConnection SqlConn = new SqlConnection(@"Data Source = (Localdb)\MSSQLLocalDB; AttachDbFilename=" +
                                              Directory.GetCurrentDirectory() + @"\HtbTs.mdf;" +
                                              "Integrated Security=SSPI;Connect Timeout=30;User Instance=False");
SqlConn.Open();
        string Delete = "DELETE FROM BagenTablo";
        SqlCommand komut = new SqlCommand(Delete, SqlConn);

        komut.ExecuteNonQuery();
        SqlConn.Close();

If the original db in your project has a data so every time when you build your project or debug it the visual studio copy the original db file into output folder如果项目中的原始 db 有数据,那么每次构建项目或调试它时,visual studio 都会将原始 db 文件复制到输出文件夹中

you can open MDF file in your project and right click on db in server window, then click New Query您可以在项目中打开 MDF 文件并在服务器窗口中右键单击 db,然后单击New Query
type and execute this query键入并执行此查询
TRUNCATE TABLE BagenTablo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM