积极答复者
DataGridView如何删除一列并更新到Access数据库中?

问题
答案
-
主要的概念是從刪除鈕去找該列的key值或代表值,找到後,先進行更新的sql語法,接著再刪除!以下給你參考
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) '按下刪除鈕 Dim oRow As System.Web.UI.WebControls.GridViewRow Dim iRowIndex As Integer oRow = CType(sender, ImageButton).NamingContainer ' GridView 中對應的 GridViewRow iRowIndex = oRow.RowIndex '對應的 RowIndex Dim strID As String = GridView1.DataKeys(iRowIndex).Values(0) '取得主索引編號 Me.sqlDataSource1.UpdateCommand = "update.....更新....." Me.sqlDataSource1.Update() Me.sqlDataSource1.DeleteCommand = "Delete......刪除......." Me.sqlDataSource1.Delete() End Sub
coding or not- 已编辑 Shinyo.her 2011年8月22日 1:34 code貼的怪怪的
- 已编辑 Mike FengModerator 2011年8月23日 14:45 Format the code
- 已建议为答案 Mike FengModerator 2011年8月23日 14:46
- 已标记为答案 Mike FengModerator 2011年8月30日 7:08
-
点右键时在mousedown事件,通过DataGridView.HitTest可以得到对应的columnindex,然后自己拼sql
http://feiyun0112.cnblogs.com/- 已标记为答案 Mike FengModerator 2011年8月30日 7:08
全部回复
-
主要的概念是從刪除鈕去找該列的key值或代表值,找到後,先進行更新的sql語法,接著再刪除!以下給你參考
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) '按下刪除鈕 Dim oRow As System.Web.UI.WebControls.GridViewRow Dim iRowIndex As Integer oRow = CType(sender, ImageButton).NamingContainer ' GridView 中對應的 GridViewRow iRowIndex = oRow.RowIndex '對應的 RowIndex Dim strID As String = GridView1.DataKeys(iRowIndex).Values(0) '取得主索引編號 Me.sqlDataSource1.UpdateCommand = "update.....更新....." Me.sqlDataSource1.Update() Me.sqlDataSource1.DeleteCommand = "Delete......刪除......." Me.sqlDataSource1.Delete() End Sub
coding or not- 已编辑 Shinyo.her 2011年8月22日 1:34 code貼的怪怪的
- 已编辑 Mike FengModerator 2011年8月23日 14:45 Format the code
- 已建议为答案 Mike FengModerator 2011年8月23日 14:46
- 已标记为答案 Mike FengModerator 2011年8月30日 7:08
-
点右键时在mousedown事件,通过DataGridView.HitTest可以得到对应的columnindex,然后自己拼sql
http://feiyun0112.cnblogs.com/- 已标记为答案 Mike FengModerator 2011年8月30日 7:08