Hi all, now I wanna share something simple about programming in C#. Yesterday, I got an error when using result of stored procedure in C#. The error is "Object cannot be cast from DBNull to other types.". It has been caused of result that produced in stored procedure is null or empty. So I give a condition while result is null, but still getting error. After searching, I just realized that giving condition betweet variable and object is different. And this is the solution of my error:
object[] ret = PXDatabase.Execute("xsREGetTax", param1, param2, param3);
if (ret[0] != DBNull.Value)
taxRate = Convert.ToDouble(ret[0]);
else
taxRate = 0;
As you can see, I execute Stored Procedure named xsREGetTax and save the result in object named ret. When ret is not null or empty, I save the value in taxRate variable.
Hope this article helps you.

Object cannot be cast from DBNull to other types
Share This
Tags
# .NET
# Komputer
Share This
5 Cara Mudah Melindungi Komputer dari Virus
Thoriq AzizOct 24, 2019Cara Mengaktifkan IIS (Internet Information Services) di Windows 10
Thoriq AzizSept 26, 2019Script Finding All Non Empty Tables in SQL Server
Thoriq AzizOct 12, 2018
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment