windows窗体删除数据的问题
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查“ 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.
您的连接字符串是否实现了安全性?尝试查看事件日志或表的权限。它可能成功连接到数据库,但没有适当的权限进行更改。如果您是管理员或域管理员,则默认情况下您应该具有访问权限。因此,您可能还需要检查域管理员组是否已添加到 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.
调试时您可能有更多数据库文件副本 - 请参阅: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