Error when trying to load control type GetInt64

ELIRDFUL 185 Reputation points

Hello everyone

I am starting programming in c sharp C#

I am trying to load the data of the controls

This is my Code

 using (var Conexion = new SqlConnection(VariablesGlobales.CadenaConexion))
                    string consultaSQL = "Select FechaFegistro, TipoFactura, TotalImporte, CodigoCliente from TblaFactura2 WHERE CodigoFactura =@CodigoFactura";

                    var comando = new SqlCommand(consultaSQL, Conexion);
                    comando.Parameters.AddWithValue("@CodigoFactura", txtCodigoFactura.Text);
                    // LD=LectorDatos

                    SqlDataReader LD = comando.ExecuteReader();

                    if (LD.Read() == true)
                        // Establecemos valores de la asignación, en el mismo orden de los valores de la consulta
                        DateTimePickerFechaRegistro.Value = LD.GetDateTime(LD.GetOrdinal("FechaFegistro"));
                        cboTipo_Factura.Text = LD.GetString(LD.GetOrdinal("TipoFactura"));
                        txtTotalImporte.Text = LD.GetDecimal(LD.GetOrdinal("TotalImporte")).ToString("N2");
                        txtCodigoCliente.Text = LD.GetInt64(LD.GetOrdinal("CodigoCliente"));

All the controls load me well,

but in this line of code an error appears and that control does not want to load.

txtCodigoCliente.Text = LD.GetInt64(LD.GetOrdinal("CodigoCliente"));

My database is: SQL Server and the field: Client Code, the data type is: bigint

The error that appears is:


The code is also put like this:
txtCodigoCliente.Text = LD.GetString(LD.GetOrdinal("CodigoCliente"));

And when I run it I get this error

I hope you can help me.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,629 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 29,026 Reputation points Microsoft Vendor

    Hi @ELIRDFUL ,

    You have to convert an int64 value to a string and then assign it to txtCodigoCliente.Text.

    txtCodigoCliente.Text = LD.GetInt64(LD.GetOrdinal("CodigoCliente")).ToString();

    Best Regards.

    Jiachen Li

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more