1

I am creating an application with MS Access as back-end. I am running delete query but it is not working Code:

conchek.ConnectionString = ConfigurationManager.ConnectionStrings["KedarnathDB"].ConnectionString;
conchek.Open();
OleDbCommand cmdc = new OleDbCommand("select * from ReceiptsTrns Where ID=@CallerName", conchek);
cmdc.Parameters.Add("@CallerName", OleDbType.Numeric).Value = txtRcptNo.Text.Trim();
OleDbDataReader rd = cmdc.ExecuteReader();

if (rd.HasRows)
{
 conchek.Close();
 con1.ConnectionString = ConfigurationManager.ConnectionStrings["KedarnathDB"].ConnectionString;
 con1.Open();
 OleDbCommand cmd = new OleDbCommand("DELETE from ReceiptsTrns Where ID=@RCName", con1);
 cmd.Parameters.Add("@RCName", OleDbType.Numeric).Value = txtRcptNo.Text.Trim();
 con1.Close();
 MessageBox.Show("Receipt deleted successfully");
}

else
{
 conchek.Close();
 MessageBox.Show("No receipt found with this number");
}

the code is running successfully but it is not reflecting the change when I see my MS Access database.

4

3 回答 3

2

您在 cmd 上缺少Execute调用。您创建它然后关闭连接,数据库永远不会运行该语句。

于 2013-06-11T06:11:49.483 回答
0
con1.ConnectionString =   ConfigurationManager.ConnectionStrings["KedarnathDB"].ConnectionString;

con1.Open();

OleDbCommand cmd = new OleDbCommand("DELETE from ReceiptsTrns Where ID=@RCName", con1);
cmd.Parameters.Add("@RCName", OleDbType.Numeric).Value = txtRcptNo.Text.Trim();
**cmd.ExecuteNoQuery();**
con1.Close();
于 2013-06-11T06:12:50.100 回答
0

对于相同的问题,我按照以下步骤操作:

1)打开您的访问数据库,

2) 单击顶部功能区中的 windows 图标,

3)点击访问选项,

4)点击信任中心设置,

5) 当内容被阻止时,单击在所有应用程序中显示消息栏

6)关闭数据库并重新打开它,

Access 将向您显示警告“数据库中的某些内容已被禁用”

7)点击选项,

8) 单击启用此内容。

您的数据库已准备好被操作...

于 2013-08-27T15:58:25.803 回答