Share via

Error when trying to load control type GetInt64

ELIRDFUL 185 Reputation points
2023-11-21T13:12:23.62+00:00

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))
                {
                    Conexion.Open();
                    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:

12

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

And when I run it I get this error
13

I hope you can help me.

Developer technologies | C#
Developer technologies | C#

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.

0 comments No comments

Answer accepted by question author

Jiachen Li-MSFT 34,241 Reputation points Microsoft External Staff
2023-11-21T13:44:02.28+00:00

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.

Was this answer helpful?

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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.