【发布时间】:2014-11-24 22:38:55
【问题描述】:
我有一个带有复选框的数据网格,可以让用户进行多次删除。如何将删除的记录存储到逗号分隔的文本文件中?我正在使用 Access 来存储我的数据
我的删除代码是
Try
con.Open()
Sql = "DELETE FROM member WHERE ID = ?"
With cmd
.Connection = con
.CommandText = Sql
.Parameters.AddWithValue("@p1", 0)
End With
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(0).FormattedValue = True Then
cmd.Parameters("@p1").Value = Convert.ToInt32(row.Cells(1).FormattedValue)
result = cmd.ExecuteNonQuery
End If
Next
If result = 0 Then
MsgBox("nothing.")
Else
MsgBox("deleted.")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
【问题讨论】:
-
请缩进您的代码以获得更易读的帖子
-
为什么不使用一组 id - 在循环中创建 id 然后用一个语句删除
-
你想在文本文件中存储什么?只是 ID 还是整个记录?
-
我已经回滚了您删除大量代码的编辑,因为没有代码,答案毫无意义。
标签: vb.net