Home / Learn programming language / object reference not set to an instance of an object in C#

object reference not set to an instance of an object in C#

There are so many things that can be annoying in programming especially things like this error. Mostly this error occur when your code look good to you but returning a null reference exception. It simply means nothing is really missing in your code but there is an intruder who is doing something else. This error happens in different ways eg

In a database

This error can happen within your query in which you specify columns name but one of them isn’t existing.

String qry = “SELECT fname,sname,email,fone,aged FROM biodata”;

Imagine aged isn’t correctly spell. This can return with something like cannot find table

But the other way this error can happen is very tricky because you might not expect it. It actually happened to me and this was how I solved the problem.

I wanted to edit one field in my database. So I open a new form and added a new text field with a button and I double clicked and wrote all the code inside and I started seeing this error of object reference not set to an instance of an object. I did everything I could but nothing. My codes were ok. Then later I thought of writing a SELECT query in my form load to test if the id I passed was inside the database though I knew it there, and the all thing started working.

This is the lesson:

Do not use UPDATE command without a SELECT command you might probably get this error. And if it continues to happen just contact me or type in your code for review. Thanks

data-matched-content-rows-num="2" data-matched-content-columns-num="2" data-matched-content-ui-type="image_stacked"

About Joseph Sam

Check Also

angularJS framework

How to crack wdms zkteco license software

WDMS is web data management server, developed by zkteco for managing their finger prints devices …

Leave a Reply

Your email address will not be published. Required fields are marked *