AYuda pls...

19/07/2004 - 19:05 por CRISTHIAN MASSA MEDINA | Informe spam
Amigos
tengo este error, me pueden ayudar para hacer esta conversión!!!

Gracias
Cast from type 'DBNull' to type 'String' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
type 'String' is not valid.

Source Error:

Preguntas similare

Leer las respuestas

#1 Gustavo The Wolf Cantero
19/07/2004 - 20:28 | Informe spam
Este error te da porque el campo que querés leer es nulo. Antes de leerlo tendrias que compararlo con System.DBNull.Value para fijarte si no es nulo.
Por ejemplo:

C#
string Valor = DataReader["campo"] == System.DBNull.Value ? "" : objDR["maxHora"];

VB.NET

Dim Valor As String = Iif(DataReader["campo"] = System.DBNull.Value, "", objDR["maxHora"])

Espero que te sirva.
Suerte!
Gustavo A. Cantero
Microsoft Certified Solution Developer
DCE Tercera Estrella


"CRISTHIAN MASSA MEDINA" wrote:

Amigos
tengo este error, me pueden ayudar para hacer esta conversión!!!

Gracias
Cast from type 'DBNull' to type 'String' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
type 'String' is not valid.

Source Error:



Respuesta Responder a este mensaje
#2 Sergio Florez M.
19/07/2004 - 20:33 | Informe spam
Estas capturando un campo directamente desde una base de datos y lo estas
almacenando en un string. Resulta que a veces ese campo esta nulo y es aqui
que te presenta el error ya que un nulo no se puede convertir a string. Lo
que debes hacer es preguntar con un if si el campo es igual a DBNull.Value,
si lo es entonces no guardes nada en el string.

Sergio Florez M.
El que persevera insiste
Medellín, Colombia
"CRISTHIAN MASSA MEDINA" <news.microsoft.com11> escribió en el mensaje
news:
Amigos
tengo este error, me pueden ayudar para hacer esta conversión!!!

Gracias
Cast from type 'DBNull' to type 'String' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
type 'String' is not valid.

Source Error:


Respuesta Responder a este mensaje
#3 CRISTHIAN MASSA MEDINA
19/07/2004 - 22:49 | Informe spam
MUCHISISIIMAS GRACIAS

"CRISTHIAN MASSA MEDINA" <news.microsoft.com11> escribió en el mensaje
news:
Amigos
tengo este error, me pueden ayudar para hacer esta conversión!!!

Gracias
Cast from type 'DBNull' to type 'String' is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Cast from type 'DBNull' to
type 'String' is not valid.

Source Error:


email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida