Dear, I have a problem when bringing two data from a table of MSSQL
. The table contains two fields that I want to fetch: CC_PreFijo
and CC_Nro
. These data in the table, as attached in the following image, are of type INT the first and type BIGINT the second:
What I do is that by DataGridView
selecting an item from it, I make a query to the table asking for those values (and others as well) but the query returns the following error:
System.FormatException: 'La cadena de entrada no tiene el formato correcto.'
And I notice this line:
int prefijo = Convert.ToInt32(sqlDataReader["prefijo"]?.ToString());
What is my mistake? From already thank you very much
The
BigInit
is equal toLong
(64-bit) in C#, try one of the following:The solution to my problem was to create the type variables
int
initialized to 0:And then I use the
TryParse
data type propertyint
taking as input the value ofsql
and parsing it to the value of the variable: