windows窗体删除数据的问题

发布于 2024-10-07 22:35:36 字数 861 浏览 2 评论 0原文

    public static void deletePersonInfo(int number)
    {
        SqlCeConnection sqlConn = null;
        SqlCeCommand cmdDelete;

        try
        {
            sqlConn = new SqlCeConnection(databaseString);
            sqlConn.Open();

            cmdDelete = new SqlCeCommand("DELETE FROM PersonInfo WHERE Number = @numb", sqlConn);
            cmdDelete.Parameters.Add(new SqlCeParameter("@numb", SqlDbType.Int)).Value = number;
            cmdDelete.ExecuteNonQuery();

        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }
        finally
        {
            if (sqlConn != null)
            {
                sqlConn.Close();
            }
        }

    }

这是我删除成员的代码。它运行良好,没有任何错误。我还检查了是否传递了正确的值。是的,确实如此。 该方法接收正确的会员号,不会给出任何错误,执行成功,但不会对数据库进行任何更改。

谁能告诉我这段代码有什么问题。

    public static void deletePersonInfo(int number)
    {
        SqlCeConnection sqlConn = null;
        SqlCeCommand cmdDelete;

        try
        {
            sqlConn = new SqlCeConnection(databaseString);
            sqlConn.Open();

            cmdDelete = new SqlCeCommand("DELETE FROM PersonInfo WHERE Number = @numb", sqlConn);
            cmdDelete.Parameters.Add(new SqlCeParameter("@numb", SqlDbType.Int)).Value = number;
            cmdDelete.ExecuteNonQuery();

        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }
        finally
        {
            if (sqlConn != null)
            {
                sqlConn.Close();
            }
        }

    }

Thats my code for deleting a member. It runs fine without any errors. I also checked whether the correct value is being passed. and yes it is.
The method receives the correct member number, does not give any error, executes successfully, but does not make any change in the database.

Can anyone tell me what is wrong with this code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伪装你 2024-10-14 22:35:36

检查“ cmdDelete.ExecuteNonQuery(); ”的返回值是否返回非零值。
如果值非零,则仅修改数据库。

Check the return value of " cmdDelete.ExecuteNonQuery(); " whether it is returning non zero value or not.
if value is nonzero then only database will be modify.

仅此而已 2024-10-14 22:35:36

您的连接字符串是否实现了安全性?尝试查看事件日志或表的权限。它可能成功连接到数据库,但没有适当的权限进行更改。如果您是管理员或域管理员,则默认情况下您应该具有访问权限。因此,您可能还需要检查域管理员组是否已添加到 sql server 框中。

Does your connection string implement security? Try and look at the event log or in the permissions for the table. It may make a successful connection to the database but not have proper permissions to make the change. If you are an admin or domain admin you should have access by default. So you might also need to check that the domain admin group was added to the sql server box.

脱离于你 2024-10-14 22:35:36

调试时您可能有更多数据库文件副本 - 请参阅:http://erikej.blogspot.com/2010/05/faq-why-does-my-changes-not-get-saved.html

You may have more copies of your database file while debugging - see this: http://erikej.blogspot.com/2010/05/faq-why-does-my-changes-not-get-saved.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文