ASP.NET - Error: La cadena de entrada no tiene el formato correcto

 
Vista:
Imágen de perfil de Marianela
Val: 30
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por Marianela (20 intervenciones) el 15/06/2019 15:27:24
Hola a todos;

Estoy realizando un proyecto para la universidad y de verdad soy algo nueva en asp.net...
Tengo un error que me da al realizar una búsqueda: "La cadena de entrada no tiene el formato correcto".
les coloco el código a ver si me pueden ayudar:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
************************ CODIGO DE LA CLASE ***********************************************************************
 
public class clsRegistroUsuario : clsConexion
    {
        // Declarar variables Gobales
 
        string tabla = "tbl_usuario";
 
        protected string tipoDocumento, numDocumento, apellido1, apellido2, nombre1, nombre2, sexo, direccion,
                         barrio, municipio, departamento, zona, telefono1, personaRemitente, status, tipoRemitente, login;
        protected int codUsuario, estrato, entidad;
        protected string fechaNac, fechaReg;
 
        // constructor de la clase 
 
        public clsRegistroUsuario(int codUsuario, int estrato, int entidad, string tipoDocumento, string numDocumento, string apellido1,
                                  string apellido2, string nombre1, string nombre2, string sexo, string direccion, string barrio, string municipio,
                                  string departamento, string zona, string telefono1, string personaRemitente, string status, string tipoRemitente, string login,
                                  string fechaNac, string fechaReg)
        {
            this.codUsuario = codUsuario;
            this.estrato = estrato;
            this.entidad = entidad;
 
            this.tipoDocumento = tipoDocumento;
            this.numDocumento = numDocumento;
            this.apellido1 = apellido1;
            this.apellido2 = apellido2;
            this.nombre1 = nombre1;
            this.nombre2 = nombre2;
            this.sexo = sexo;
            this.direccion = direccion;
            this.barrio = barrio;
            this.municipio = municipio;
            this.departamento = departamento;
            this.zona = zona;
            this.telefono1 = telefono1;
            this.personaRemitente = personaRemitente;
            this.status = status;
            this.tipoRemitente = tipoRemitente;
            this.login = login;
 
            this.fechaNac = fechaNac;
            this.fechaReg = fechaReg;
 
        }
 
        // metodos de la clase 
 
        // variables int
        public int CodUsuario
        {
            set { codUsuario = value; }
            get { return codUsuario; }
        }
 
        public int Estrato
        {
            set { estrato = value; }
            get { return estrato; }
        }
        public int Entidad
        {
            set { entidad = value; }
            get { return entidad; }
        }
 
        // variables string
 
        public string TipoDocumento
        {
            set { tipoDocumento = value; }
            get { return tipoDocumento; }
        }
 
        public string NumDocumento
        {
            set { numDocumento = value; }
            get { return numDocumento; }
        }
        public string Apellido1
        {
            set { apellido1 = value; }
            get { return apellido1; }
        }
        public string Apellido2
        {
            set { apellido2 = value; }
            get { return apellido2; }
        }
        public string Nombre1
        {
            set { nombre1 = value; }
            get { return nombre1; }
        }
        public string Nombre2
        {
            set { nombre2 = value; }
            get { return nombre2; }
        }
        public string Sexo
        {
            set { sexo = value; }
            get { return sexo; }
        }
        public string Direccion
        {
            set { direccion = value; }
            get { return direccion; }
        }
        public string Barrio
        {
            set { barrio = value; }
            get { return barrio; }
        }
        public string Municipio
        {
            set { municipio = value; }
            get { return municipio; }
        }
        public string Departamento
        {
            set { departamento = value; }
            get { return departamento; }
        }
        public string Zona
        {
            set { zona = value; }
            get { return zona; }
        }
        public string Telefono1
        {
            set { telefono1 = value; }
            get { return telefono1; }
        }
        public string PersonaRemitente
        {
            set { personaRemitente = value; }
            get { return personaRemitente; }
        }
        public string Status
        {
            set { status = value; }
            get { return status; }
        }
        public string TipoRemitente
        {
            set { tipoRemitente = value; }
            get { return tipoRemitente; }
        }
        public string Login
        {
            set { login = value; }
            get { return login; }
        }
 
        // variables  de Fecha
 
        public string FechaNac
        {
            set { fechaNac = value; }
            get { return fechaNac; }
        }
 
        public string FechaReg
        {
            set { fechaReg = value; }
            get { return fechaReg; }
        }
 
 
// verifica si existe el registro (realiza una búsqueda)
        public bool existe(int valor)
        {
            conectar();
            abrirBD();
            adaptadorBD(tabla);
 
            DataRow fila;
 
            int x = Data.Tables[tabla].Rows.Count - 1;
            for (int i = 0; i <= x; i++)
            {
                fila = Data.Tables[tabla].Rows[i];
 
                if (int.Parse(fila["codUsuario"].ToString().Trim()) == valor)
                {
                    CodUsuario = int.Parse(fila["codUsuario"].ToString().Trim());
                    Estrato = int.Parse(fila["estrato"].ToString().Trim());
                    Entidad = int.Parse(fila["entidad"].ToString().Trim());
 
                    TipoDocumento = fila["tipoDocumento"].ToString();
                    NumDocumento = fila["numDocumento"].ToString();
                    Apellido1 = fila["apellido1"].ToString();
                    Apellido2 = fila["apellido2"].ToString();
                    Nombre1 = fila["nombre1"].ToString();
                    Nombre2 = fila["nombre2"].ToString();
                    Sexo = fila["sexo"].ToString();
                    Direccion = fila["direccion"].ToString();
                    Barrio = fila["barrio"].ToString();
                    Municipio = fila["municipio"].ToString();
                    Departamento = fila["departamento"].ToString();
                    Zona = fila["zona"].ToString();
                    Telefono1 = fila["telefono1"].ToString();
                    PersonaRemitente = fila["personaRemitente"].ToString();
                    Status = fila["status"].ToString();
                    TipoRemitente = fila["tipoRemitente"].ToString();
                    Login = fila["login"].ToString();
 
                    FechaNac = fila["fechaNac"].ToString();
                    FechaReg = fila["fechaReg"].ToString();
 
                    return true;
                }
            }
            // El registro no existe
            return false;
        }
 
 
********************************************** CODIGO DEL FORMULARIO *******************************************
 
  //Botón Buscar
        protected void btnbuscar_Click(object sender, EventArgs e)
        {
           clsRegistroUsuario registroUsuario = new clsRegistroUsuario(0, 0, 0, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
 
            try
            {
                if (txtbuscar.Text.Trim() == string.Empty)
                {
                    lblbuscar.Text = "No se puede realizar una búsqueda con valores vacíos";
                }
                else if (registroUsuario.existe(int.Parse(txtcodUsuario.Text.Trim()))) //Búsqueda por ID
                        {
                    //captura los atributos devueltos por la busqueda
 
                    txtcodUsuario.Text = registroUsuario.CodUsuario.ToString();
                    dropEstrato.SelectedIndex = dropEstrato.Items.IndexOf(dropEstrato.Items.FindByValue(registroUsuario.Estrato.ToString()));
                    dropEntidad.SelectedIndex = dropEntidad.Items.IndexOf(dropEntidad.Items.FindByValue(registroUsuario.Entidad.ToString()));
 
                    dropTipoDocum.SelectedIndex = dropTipoDocum.Items.IndexOf(dropTipoDocum.Items.FindByValue(registroUsuario.TipoDocumento.ToString()));
                    txtnumDocumento.Text = registroUsuario.NumDocumento;
                    txtapellido1.Text = registroUsuario.Apellido1;
                    txtapellido2.Text = registroUsuario.Apellido2;
                    txtnombre1.Text = registroUsuario.Nombre1;
                    txtnombre2.Text = registroUsuario.Nombre2;
                    dropSexo.SelectedIndex = dropSexo.Items.IndexOf(dropSexo.Items.FindByValue(registroUsuario.Sexo.ToString()));
                    txtdireccion.Text = registroUsuario.Direccion;
                    txtbarrio.Text = registroUsuario.Barrio;
                    dropMunicipio.SelectedIndex = dropMunicipio.Items.IndexOf(dropMunicipio.Items.FindByValue(registroUsuario.Municipio.ToString()));
                    dropDpartamento.SelectedIndex = dropDpartamento.Items.IndexOf(dropDpartamento.Items.FindByValue(registroUsuario.Departamento.ToString()));
                    dropZona.SelectedIndex = dropZona.Items.IndexOf(dropZona.Items.FindByValue(registroUsuario.Zona.ToString()));
                    txttelefono.Text = registroUsuario.Telefono1;
                    txtpersonaRemitente.Text = registroUsuario.PersonaRemitente;
                    DropStatus.SelectedIndex = DropStatus.Items.IndexOf(DropStatus.Items.FindByValue(registroUsuario.Status.ToString()));
                    dropTipoRemitente.SelectedIndex = dropTipoRemitente.Items.IndexOf(dropTipoRemitente.Items.FindByValue(registroUsuario.TipoRemitente.ToString()));
 
                    txtfechaNacimiento.Text = registroUsuario.FechaNac;
                    txtfechaRegistro.Text = registroUsuario.FechaReg;
 
 
                            lblestado.Text = "Registro encontrado";
                            btnmodificar.Enabled = true;
                            btneliminar.Enabled = true;
                            btncancelar.Enabled = true;
                            btnnuevo.Enabled = false;
                        }
                        else
                        {
 
                            lblestado.Text = "No se encontraron resultados";
                        }
                    }
            catch (Exception ex)
            {
                lblestado.Text = "Error al buscar:   " + ex.Message;
            }
        }
**************************************************************************************************************************

No se si mis problemas sean los dropbox (dropEstrato, y dropEntidad) que son enteros y las fechas reciben desde datatime..... pero no puedo realizar una búsqueda, tampoco puedo agregar registro nuevo.
La base de datos en en Access 2019 y ASP.Net 2015
me imagino que esta en unos de los formatos.

Ayudenme por favor...
Muchas Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Wilfredo Patricio Castillo
Val: 169
Oro
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por Wilfredo Patricio Castillo (75 intervenciones) el 16/06/2019 01:13:39
Has logrado ubicar la línea exacta dónde salta el error?.
Le has hecho un seguimiento linea a linea?.

No podemos adivinar mirando todo tu código.

Saludos cordiales,
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Marianela Blanco
Val: 30
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por Marianela Blanco (20 intervenciones) el 17/06/2019 15:00:12
Hola...
Haciendo descarte, aqui es donde muestra la línea del error:

Error de servidor en la aplicación '/'.
La cadena de entrada no tiene el formato correcto.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.

Detalles de la excepción: System.FormatException: La cadena de entrada no tiene el formato correcto.

Error de código fuente:


1
2
3
4
5
Línea 391:                    lblbuscar.Text = "No se puede realizar una búsqueda con valores vacíos";
Línea 392:                }
Línea 393:                else if (registroUsuario.existe(int.Parse(txtcodUsuario.Text.ToString().Trim()))) //Búsqueda por ID
Línea 394:                        {
Línea 395:                    //captura los atributos devueltos por la busqueda


esta es el método de "Existe":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public bool existe(int valor)
{
    conectar();
    abrirBD();
    adaptadorBD(tabla);
 
    DataRow fila;
 
    int x = Data.Tables[tabla].Rows.Count - 1;
    for (int i = 0; i <= x; i++)
    {
        fila = Data.Tables[tabla].Rows[i];
 
            if (int.Parse(fila["codUsuario"].ToString().Trim()) == valor)
        {
        CodUsuario = int.Parse(fila["codUsuario"].ToString().Trim());
        Estrato = int.Parse(fila["estrato"].ToString());
        Entidad = int.Parse(fila["entidad"].ToString());
 
        TipoDocumento = fila["tipoDocumento"].ToString();
        NumDocumento = fila["numDocumento"].ToString();
        Apellido1 = fila["apellido1"].ToString();
        Apellido2 = fila["apellido2"].ToString();
        Nombre1 = fila["nombre1"].ToString();
        Nombre2 = fila["nombre2"].ToString();
        Sexo = fila["sexo"].ToString();
        Direccion = fila["direccion"].ToString();
        Barrio = fila["barrio"].ToString();
        Municipio = fila["municipio"].ToString();
        Departamento = fila["departamento"].ToString();
        Zona = fila["zona"].ToString();
        Telefono1 = fila["telefono1"].ToString();
        PersonaRemitente = fila["personaRemitente"].ToString();
        Status = fila["status"].ToString();
        TipoRemitente = fila["tipoRemitente"].ToString();
        Login = fila["login"].ToString();
 
      //  FechaNac = fila["fechaNac"].ToString();
     //   FechaReg = fila["fechaReg"].ToString();


comenté las fechas a ver si ese era el error y nada... ahora no veo cual es el formato incorrecto.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Javier
Val: 33
Ha disminuido 1 puesto en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por Javier (17 intervenciones) el 17/06/2019 19:08:34
Difícil saber así como lo expresas, no tenemos por ejemplo la estructura de la tabla donde estas trayendo los datos, pon un punto de interrupción en el codigo y ve paso a paso para que veas en que parte te marca el error y así seria mas fácil poder ayudar.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Javier
Val: 33
Ha disminuido 1 puesto en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por Javier (17 intervenciones) el 18/06/2019 00:47:14
Que valor lleva

1
txtcodUsuario.Text
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 165
Oro
Ha mantenido su posición en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

Error: La cadena de entrada no tiene el formato correcto

Publicado por miguelZ (72 intervenciones) el 18/06/2019 22:27:32
Lo mas recomendable es que reduscas la cantidad de campos a guardar y realices todo el ciclo con estos elementos

Digamos
CodigoDeUsuario
Nombre
Apellido1


ya cuando establescas la creacion y actualizacion de estos campos puedes agregar entidades mas complejas.

Asi si tienes un error es mas facil identificarlo.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar