Convert datarowview into C #

0

Good evening I continue, passing my system from Vb to C #, now I have this error in this conversion, I visualized it in this way:

Dim aoRow As dsmstpsnal.GetDetaPsnal01Row = CType(CType(e.Row, DataRowView).Row, dsmstpsnal.GetDetaPsnal01Row)

And the result once the conversion was obtained, I had it that way

e.Value = cInt(aoRow.IDCODEMP  )

Now I did the following in C #

dshojasadmision.tblAdmonClienteRow CustRow = (dshojasadmision.tblAdmonClienteRow)e.Row;
    e.Value = CustRow.FechaNacimiento;

I get a conversion error that is the following,

  

System.InvalidCastException was unhandled by user code
  HResult = -2147467262 Message = Unable to convert an object of type   'System.Data.DataRowView' to the type 'tblAdmonClienteRow'.

How is the code in C# if it exists?

    
asked by alfredo.avmb 22.12.2017 в 06:55
source

1 answer

0

When converting the code, you missed a stage.

With your code in VB.NET:

Dim aoRow As dsmstpsnal.GetDetaPsnal01Row = CType(CType(e.Row, DataRowView).Row, dsmstpsnal.GetDetaPsnal01Row)

... the stages you follow are:

  • Convert e.Row to DataRowView .
  • Read property Row of DataRowView , which returns a DataRow .
  • Convert DataRow to dsmstpsnal.GetDetaPsnal01Row .
  • But with your C # code:

    dshojasadmision.tblAdmonClienteRow CustRow = (dshojasadmision.tblAdmonClienteRow)e.Row;
    

    ... you are trying to move directly from a DataRowView to your class dshojasadmision.tblAdmonClienteRow . You forgot the intermediary stage of extracting the DataRow using the property Row of DataRowView .

    Actually, the code equivalent to what you have in VB.NET is the following:

    dshojasadmision.tblAdmonClienteRow CustRow =
        (dshojasadmision.tblAdmonClienteRow)((DataRowView)e.Row).Row;
    
        
    answered by 22.12.2017 в 15:10