开发者

Problem in deleting data in windows form

    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)
           开发者_JAVA技巧 {
                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.


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜