Conversion from type 'DBNull' to type 'String' is not valid

user3571305

i am receiving this problem

Conversion from type 'DBNull' to type 'String' is not valid.

Line 501: hfSupEmail.Value = dt.Rows(0)("SupEmail")

i am very new to this, i am not really sure what is the exact problem could someone guide me?

Many thanks

Joel Coehoorn

The quick and dirty fix:

hfSupEmail.Value = dt.Rows(0)("SupEmail").ToString()

or for C#:

hfsupEmail.Value = dt.Rows[0]["SupEmail"].ToString();

This works very well when your eventual target and the source data are already strings. This is because any extra .ToString() call for something that's already a string will generally be optimized by the jitter into a no-op, and if it's NULL the resulting DBNull.Value.ToString() expression produces the empty string you want.

However, if you're working with non-string types, you may end up doing significant extra work, especially with something like a DateTime or numeric value where you want specific formatting. Remember, internationalization concerns mean parsing and composing date and number values are actually surprisingly expensive operations; doing "extra" work to avoid those operations is often more than worth it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Conversion from type 'DBNull' to type 'String' is not valid

From Dev

Conversion from type 'DBNull' to type 'String' is not valid vb.net

From Dev

Conversion from type 'DBNull' to type 'Double' is not valid

From Dev

Conversion from type 'DBNull' to type 'String' is not valid when inserting data from datagridview to sql database

From Dev

Conversion from type 'DBNull' to type 'String' is not valid when inserting data from datagridview to sql database

From Dev

How to handle Conversion from type 'DBNull' to type 'Integer' is not valid

From Dev

Conversion from type 'DBNull' to type 'Date' is not valid on tryparse

From Dev

Another "conversion from type DBNull to type Date not valid" issue

From Dev

Conversion from type 'Button' to type string is not valid

From Dev

Conversion from type 'Button' to type string is not valid

From Dev

Conversion from type 'DBNull' to type 'Double' is not valid when returns empty data

From Dev

Conversion from string "." to type 'Decimal' is not valid

From Dev

Conversion From String To Type 'Date' Is Not Valid

From Dev

Conversion from string to type Double is not valid

From Dev

Conversion from string "I" to type 'Boolean' is not valid

From Dev

Error: Conversion from string "" to type 'Double' is not valid

From Dev

Conversion from "string" to Type 'Boolean' is not valid

From Dev

Conversion From String To Type 'Date' Is Not Valid

From Dev

Conversion from string to type Double is not valid

From Dev

"Conversion from string to type Double is not valid" error VB.NET

From Dev

"Additional information: Conversion from string "yes" to type 'Boolean' is not valid."

From Dev

Conversion from string "" to type 'Double' is not valid In .NET Fiddle's VB

From Dev

Conversion from string "X.X" to type 'Double' is not valid

From Dev

Conversion from string "‎8/‎5/‎2014" to type 'Date' is not valid

From Dev

Conversion from string "" to type 'Integer' is not valid on a for each statement

From Dev

How to get rid of Conversion from string "admin" to type 'Double' is not valid

From Dev

Conversion from string "-1" to type 'Integer' is not valid, but the String value IS a valid int

From Dev

Conversion from type 'Object(,)' to type 'String' is not valid when deleting cells from vb.net

From Dev

Conversion from string to generic type

Related Related

  1. 1

    Conversion from type 'DBNull' to type 'String' is not valid

  2. 2

    Conversion from type 'DBNull' to type 'String' is not valid vb.net

  3. 3

    Conversion from type 'DBNull' to type 'Double' is not valid

  4. 4

    Conversion from type 'DBNull' to type 'String' is not valid when inserting data from datagridview to sql database

  5. 5

    Conversion from type 'DBNull' to type 'String' is not valid when inserting data from datagridview to sql database

  6. 6

    How to handle Conversion from type 'DBNull' to type 'Integer' is not valid

  7. 7

    Conversion from type 'DBNull' to type 'Date' is not valid on tryparse

  8. 8

    Another "conversion from type DBNull to type Date not valid" issue

  9. 9

    Conversion from type 'Button' to type string is not valid

  10. 10

    Conversion from type 'Button' to type string is not valid

  11. 11

    Conversion from type 'DBNull' to type 'Double' is not valid when returns empty data

  12. 12

    Conversion from string "." to type 'Decimal' is not valid

  13. 13

    Conversion From String To Type 'Date' Is Not Valid

  14. 14

    Conversion from string to type Double is not valid

  15. 15

    Conversion from string "I" to type 'Boolean' is not valid

  16. 16

    Error: Conversion from string "" to type 'Double' is not valid

  17. 17

    Conversion from "string" to Type 'Boolean' is not valid

  18. 18

    Conversion From String To Type 'Date' Is Not Valid

  19. 19

    Conversion from string to type Double is not valid

  20. 20

    "Conversion from string to type Double is not valid" error VB.NET

  21. 21

    "Additional information: Conversion from string "yes" to type 'Boolean' is not valid."

  22. 22

    Conversion from string "" to type 'Double' is not valid In .NET Fiddle's VB

  23. 23

    Conversion from string "X.X" to type 'Double' is not valid

  24. 24

    Conversion from string "‎8/‎5/‎2014" to type 'Date' is not valid

  25. 25

    Conversion from string "" to type 'Integer' is not valid on a for each statement

  26. 26

    How to get rid of Conversion from string "admin" to type 'Double' is not valid

  27. 27

    Conversion from string "-1" to type 'Integer' is not valid, but the String value IS a valid int

  28. 28

    Conversion from type 'Object(,)' to type 'String' is not valid when deleting cells from vb.net

  29. 29

    Conversion from string to generic type

HotTag

Archive