myTable
行を削除したいが削除したくないテーブル( )があります。を使用して期限切れにしますmyTable.ActiveFlag
。したがって、から行を「削除」するときにmyTable
、を実行したいと思いますUPDATE myTable SET ActiveFlag = 0 WHERE id = @rowId
。
DevExpressGridcontrol
を使用してこれを行うための最良の方法は何GridView
ですか?
私は現在:
Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
//'TODO: Remove Row
End If
e.Handled = True
End Sub
ここでストアドプロシージャまたはSQLステートメントを実行することを考えていましたが、これを実行するためのより簡単な、またはより適切な方法はありますか?
これが私の最終的なコードの基本バージョンです:
Private Sub gcMyTableMaintenance_EmbeddedNavigator_ButtonClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.NavigatorButtonClickEventArgs) Handles gcMyTableMaintenance.EmbeddedNavigator.ButtonClick
If e.Button.ButtonType = DevExpress.XtraEditors.NavigatorButtonType.Remove Then
Dim iMyTableId As Int32 = 0
iMyTableId = gvMyTableMaintenance.GetFocusedRowCellValue("id")
Using conn As New SqlConnection(MyConnectionString)
Using lCmd As New SqlCommand()
Try
lCmd.Connection = conn
lCmd.CommandType = CommandType.StoredProcedure
lCmd.CommandText = "ExpireFromMyTable"
lCmd.Parameters.AddWithValue("@myTableId", iMyTableId)
conn.Open()
lCmd.ExecuteNonQuery()
conn.Close()
//'Need to delete from
gvMyTableMaintenance.DeleteRow(gvMyTableMaintenance.FocusedRowHandle)
Catch ex As Exception
//'Handle Exception
End Try
End Using
End Using
End If
e.Handled = True
End Sub