c#连接sqlserver数据库怎么实现多选删除 前面多选框 打钩之后点删除选中的就能删除 求详

c#连接sqlserver数据库怎么实现多选删除 前面多选框 打钩之后点删除选中的就能删除 求详,第1张

这个是我这边实例的写法,你根据你你的情况改改:

#region[删除]

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 = 0i <dataGridView1.Rows.Counti++)

{

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.ToShortDateString() + "')"

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 = 0i <dataGridView1.Rows.Counti++)

{

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.ToShortDateString() + "')"

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

前端:

$sql="select * from 你的表名"

$result=mysql_query($sql)

while($result){

echo" <table>"

echo"<tr>"

echo"<td>"

echo"$result[ 你查询的数据名称 ]"

echo "<a herf='delete.php?id= $result[id] '>删除</a>"

echo"</td>"

echo"</tr>"

echo"</table>"

}

后台:delete.php

if(isset(GET[ID])){

$SQL="DELETE FROM 你的表名 WHERE ID ='."GET[ID]".'"

MYSQL_QUERY($SQL)

if(mysql_affect_rows($sql)>0){

echo"<script>alert('删除成功')location.href='javascript:go(-1)'</script>"

}

}

注:手机端打的,符号有些可能弄成中文的了,改过来就行


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9916896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存