gpt4 book ai didi

c# - 从 OleDB C# 中删除数据

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:16 25 4
gpt4 key购买 nike

我的数据库中的列是 [CusName]、[CusNo]、[CusAdvance]、[TotalAmount]、[ID][CusItem]。我从 textBox4.Text 中获取要删除的客户名称的输入。我已经根据从你们那里得到的信息修改了代码。但仍然没有删除条目。它们仍然保留在数据库中。

我的代码:

void Button1Click(object sender, EventArgs e)
{
try
{
OleDbConnection delConn = new
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:/NavneethCollection.accdb;Persist Security Info=False;");
delConn.Open();
String delQuery = "DELETE FROM NavColl WHERE [CusName]= @CustName";
OleDbCommand delcmd = new OleDbCommand();
delcmd.CommandText = delQuery;
delcmd.Connection = delConn;
delcmd.Parameters.AddWithValue("@CustName", textBox4.Text);
delcmd.ExecuteNonQuery();
MessageBox.Show("Customer has been successfully removed!");
}
catch(Exception exc)
{
MessageBox.Show("Error: "+exc.Message);
}
}

最佳答案

在你的删除命令中你应该只使用

try
{
OleDbConnection delConn = new
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:/NavneethCollection.accdb;Persist Security Info=False;");
delConn.Open();
String delQuery = "DELETE FROM NavColl WHERE [CusName]= @CustName";
OleDbCommand delcmd = new OleDbCommand();
delcmd.CommandText = delQuery;
delcmd.Connection = delConn;
delcmd.Parameters.AddWithValue("@CustName", textBox4.Text);
delcmd.ExecuteNonQuery();
MessageBox.Show("Customer has been successfully removed!");
}
catch(Exception exc)
{
MessageBox.Show("Error: "+exc.Message);
}

关于c# - 从 OleDB C# 中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43394957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com