使用C#卸载软件时如何从数据库中删除表 [英] how to delete table from database when a software is uninstalling using c#

查看:101
本文介绍了使用C#卸载软件时如何从数据库中删除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我使用后端SQL和ms访问的c#创建了一个桌面应用程序.现在,如果有人卸载此应用程序,我想删除数据库中的一个表.有可能这样做吗?如果可能的话,请给我这个主意....


谢谢
Sujith.

Hai,

I have created one desktop application using c# with back end sql and ms access. Now if anyone uninstall this application, i want to delete one of my tables in database. Is it possible to do that? if it is possible please give me the idea....


Thanks
Sujith.

推荐答案

阅读此内容

我从这个中学到了相同的东西

http://edndoc.esri.com/arcobjects/9.2/NET/0df20605-b457-42d6-b63c-341a3824474a.htm [ ^ ]

希望这会有所帮助,如果是,则接受并投票回答,否则返回您的查询
--Rahul D.
Read this

I learned the same thing from this

http://edndoc.esri.com/arcobjects/9.2/NET/0df20605-b457-42d6-b63c-341a3824474a.htm[^]

Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.


检查以下链接:

http://mattbrett.com/blog/development/2011/how-to-uninstall-bbpress /

http://www.dotnetperls.com/list-remove

http://www.eggheadcafe.com/community/csharp/2/10069013/uninstall-a-proram-by-using-c.aspx
使用VS.NET中创建的安装程序升级应用程序时,卸载以前安装的应用程序1
http://stackoverflow.com/questions/5170429/deleting-database-from-c-sharp
check following links:

http://mattbrett.com/blog/development/2011/how-to-uninstall-bbpress/

http://www.dotnetperls.com/list-remove

http://www.eggheadcafe.com/community/csharp/2/10069013/uninstall-a-proram-by-using-c.aspx
Uninstall a Previously Installed Application when Upgrading an Application with Setups created in VS.NET- Part 1
http://stackoverflow.com/questions/5170429/deleting-database-from-c-sharp




如果可以的话请尝试...

Hi,

Try this if could help...

///
// dbName = DataBase Name
// dtName = DataTable Name
// wConn = Web config Connection 
// <summary>
//  Warning Delete table from database at run time 
//  Use this properly...
//  Advised to backup your target table to drop before executing this...
//  Required to execute:  Administration Rights
// </summary>
// <param name="dbName"></param>
// <param name="dtName"></param>
// <param name="wConn"></param>
public virtual bool DropTable(string dbName, string dtName, string wConn)
{
    bool retValue = false;
    StringBuilder sb = new StringBuilder();
    sb.Append("USE [" + dbName.Trim() + "]" + "\r\n ");
    sb.Append("GO" +   "\r\n ");
    sb.Append("IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + dtName + "]') AND type in (N'U'))" +   "\r\n ");
    sb.Append("DROP TABLE [dbo].[" + dtName.Trim() + "]"  + "\r\n ");
    sb.Append("GO");
    string sbStr = sb.ToString();
    SqlConnection conn = new SqlConnection((wConn + ";Connect Timeout=300; pooling='true'; Max Pool Size=300"));
    SqlCommand cmd = new SqlCommand(sbStr);
    try
    {
        cmd.Connection = conn;
        cmd.Connection.Open();
        cmd.CommandTimeout = 300;
        cmd.ExecuteScalar();
        retValue = true;
        cmd.Dispose();
        conn.Close();
    }
    catch (Exception)
    {
        retValue = false;
        return retValue;
    }
        return retValue;
 }



请投票表决是否有帮助,以便其他人可以考虑作为答案...

编码愉快...



Please vote if could help so that others may consider as an answer...

Happy coding...


这篇关于使用C#卸载软件时如何从数据库中删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆