Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion failed when converting the varchar value 'null' to data type int

I'm getting values from database to a aspx page. while getting values of one column, the column is throwing a value like...

null,402,2912,2909,2910,2913,2911,2914,2915,2388,2389,2390,
2391,2964,2965,2392,2393,2394,2395,2397

Now it throws a exception

Conversion failed when converting the varchar value 'null' to data type int.

But I want all the other values of the column except the null...

Is there any way to convert this 'null' to '0', but still all the other values should exist.

like image 623
user1199023 Avatar asked Aug 28 '26 22:08

user1199023


1 Answers

Make your data type Nullable<int> instead of int to allow the converted int nullable values, or on the sql select statement you can do that: ISNULL(yourcolumn, 0) to convert null to 0.

like image 169
Mahmoud Gamal Avatar answered Aug 31 '26 16:08

Mahmoud Gamal