Thursday, July 30, 2015

Cannot convert null to 'bool' because it is a non-nullable value type

I got following error: Exception Details: Microsoft.CSharp.
RuntimeBinder.RuntimeBinderException: Cannot convert null to 'bool' because it is a non-nullable value type, today while referencing a .dll file and creating object of a class.

I could hardly solve the issue by just looking into the stack trace. But I could back trace the changes I had made and point out the spot it occurred at. I found that it was caused by improper passing of null object where constructor of my repository class expected object. Some hit and trail got me out of the issue. Please write in the comments if you have faced the exceptions and solved it.

Thank you.

Wednesday, July 29, 2015

Convert datetime to MMDDYY format in sql server

If you ever needed to convert datetime field to MMDDYY format in sql server, read on. I am going to present you a quick tips on how to get date or datetime field in sql server in MMDDYY format. Let's do it step by step.

First of all I would like to remind you to learn how to convert date to different date string using Convert function of ms sql server. This will prepare background for the technique used in this article.

For the sake of easiness, I will use current date and time as the date field we would like to convert to MMDDYY format. As you all know, getdate() returns you current date and time, as below:

select getdate() as Today
Output is: 2015/07/29 05:00:47.563

First we will get this date in mm/dd/yyyy format. Here is how:
select convert(varchar(10),getdate(),1)
Output is: 07/29/15

Now we are almost there! Let replace those forward slashes (/) with empty string. And voila! We have MMDDYY. Here is the script:

select replace(convert(varchar(10),getdate(),1),'/','')
Output is: 072915

All the steps are put together below.
















Now we have successfully converted datetime field in sql server into MMDDYY format.

Popular Posts

Recent Articles