C#如何删除listview中的整行?并且修改结果保存到Access数据库中。求代码。谢谢大神
1个回答
展开全部
if (e.ClickedItem.Text == "删除")
{
if (dataGridView1.Rows.Count > 0)
{
if (账套号.Text == "")
{
DialogResult result = MessageBox.Show("是否删除所选产品的所有信息?", "产品删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[dataGridView1.Columns["选择"].Index].EditedFormattedValue == true)
{
if (dataGridView1.Rows[i].Cells[dataGridView1.Columns["审核人"].Index].Value.ToString() == "")
{
string cInvCode = dataGridView1.Rows[i].Cells[dataGridView1.Columns["存货编码"].Index].Value.ToString();
Update_String = "delete from Inventory where cInvCode='" + cInvCode + "'";
Update_String0 = "delete from Attribute where cInvCode='" + cInvCode + "'";
Update_String1 = "insert into UA_Log(OperatorId,OperatorName,cSituation,ComputerName,IPAddress,MacAddress,dInTime)values('" + FrmMain.Send_Data + "','" + FrmMain.Send_Data_1 + "','删除产品[" + cInvCode + "]信息成功!','" + FrmLogin.ComputerName + "','" + FrmLogin.IPAddress + "','" + FrmLogin.MACAddress + "','" + DateTime.Now.ToString() + "')";
SQL_Linker.SQL_Update(Update_String, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String0, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String1, FrmMain.Send_Data_3);
}
else
{
MessageBox.Show("请先弃审后再删除!","软件提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
}
}
}
TreeView_Select();
}
catch { }
}
else
{
return;
}
}
else
{
DialogResult result = MessageBox.Show("是否删除所选产品的账套信息?", "产品删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[dataGridView1.Columns["选择"].Index].EditedFormattedValue == true)
{
string cInvCode = dataGridView1.Rows[i].Cells[dataGridView1.Columns["存货编码"].Index].Value.ToString();
Update_String0 = "delete from Attribute where cInvCode='" + cInvCode + "' and cAcc_Id='" + 账套号.Text + "'";
Update_String1 = "insert into UA_Log(OperatorId,OperatorName,cSituation,ComputerName,IPAddress,MacAddress,dInTime)values('" + FrmMain.Send_Data + "','" + FrmMain.Send_Data_1 + "','删除["+账套号.Text+"]产品[" + cInvCode + "]信息成功!','" + FrmLogin.ComputerName + "','" + FrmLogin.IPAddress + "','" + FrmLogin.MACAddress + "','" + DateTime.Now.ToString() + "')";
SQL_Linker.SQL_Update(Update_String0, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String1, FrmMain.Send_Data_3);
}
}
TreeView_Select();
}
catch { }
}
else
{
return;
}
}
}
else
{
MessageBox.Show("没有可删除的数据!", "软件提示", MessageBoxButtons.OK);
return;
}
}
#endregion
{
if (dataGridView1.Rows.Count > 0)
{
if (账套号.Text == "")
{
DialogResult result = MessageBox.Show("是否删除所选产品的所有信息?", "产品删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[dataGridView1.Columns["选择"].Index].EditedFormattedValue == true)
{
if (dataGridView1.Rows[i].Cells[dataGridView1.Columns["审核人"].Index].Value.ToString() == "")
{
string cInvCode = dataGridView1.Rows[i].Cells[dataGridView1.Columns["存货编码"].Index].Value.ToString();
Update_String = "delete from Inventory where cInvCode='" + cInvCode + "'";
Update_String0 = "delete from Attribute where cInvCode='" + cInvCode + "'";
Update_String1 = "insert into UA_Log(OperatorId,OperatorName,cSituation,ComputerName,IPAddress,MacAddress,dInTime)values('" + FrmMain.Send_Data + "','" + FrmMain.Send_Data_1 + "','删除产品[" + cInvCode + "]信息成功!','" + FrmLogin.ComputerName + "','" + FrmLogin.IPAddress + "','" + FrmLogin.MACAddress + "','" + DateTime.Now.ToString() + "')";
SQL_Linker.SQL_Update(Update_String, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String0, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String1, FrmMain.Send_Data_3);
}
else
{
MessageBox.Show("请先弃审后再删除!","软件提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
}
}
}
TreeView_Select();
}
catch { }
}
else
{
return;
}
}
else
{
DialogResult result = MessageBox.Show("是否删除所选产品的账套信息?", "产品删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[dataGridView1.Columns["选择"].Index].EditedFormattedValue == true)
{
string cInvCode = dataGridView1.Rows[i].Cells[dataGridView1.Columns["存货编码"].Index].Value.ToString();
Update_String0 = "delete from Attribute where cInvCode='" + cInvCode + "' and cAcc_Id='" + 账套号.Text + "'";
Update_String1 = "insert into UA_Log(OperatorId,OperatorName,cSituation,ComputerName,IPAddress,MacAddress,dInTime)values('" + FrmMain.Send_Data + "','" + FrmMain.Send_Data_1 + "','删除["+账套号.Text+"]产品[" + cInvCode + "]信息成功!','" + FrmLogin.ComputerName + "','" + FrmLogin.IPAddress + "','" + FrmLogin.MACAddress + "','" + DateTime.Now.ToString() + "')";
SQL_Linker.SQL_Update(Update_String0, FrmMain.Send_Data_3);
SQL_Linker.SQL_Update(Update_String1, FrmMain.Send_Data_3);
}
}
TreeView_Select();
}
catch { }
}
else
{
return;
}
}
}
else
{
MessageBox.Show("没有可删除的数据!", "软件提示", MessageBoxButtons.OK);
return;
}
}
#endregion
追问
答非所问
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询