Error in passing parameters C #

0

I have the following error:

Error   1   Cannot implicitly convert type 'System.DateTime' to 'string'

In the following code:

t.Codigo = GetValorDateTime(tabela, i, "DataDeContrato", DateTime.MinValue);

    public DateTime GetValorDateTime(DataTable pDados, int pLinha, String pNomeColuna, DateTime pValorPadrao)
    {
        DateTime retorno = pValorPadrao;
        if (pDados.Rows.Count > pLinha)
        {
            if (pDados.Columns.Contains(pNomeColuna))
            {
                object valor = pDados.Rows[pLinha].ItemArray[pDados.Columns[pNomeColuna].Ordinal];
                if (valor != null)
                    retorno = Convert.ToDateTime(valor);
            }
        }
        return retorno;
    }
    
asked by anonymous 08.11.2017 / 12:44

1 answer

1

Your t.Codigo must be of type string, and the method return is of type DateTime .

You can try doing this:

t.Codigo = GetValorDateTime(tabela, i, "DataDeContrato", DateTime.MinValue).ToString();

But I believe that this is not what you want, a DateTime does not make sense as a code of anything. Maybe you're missing the property you want to set, possibly:

t.DataDeContrato = GetValorDateTime(tabela, i, "DataDeContrato", DateTime.MinValue);
    
08.11.2017 / 12:55