vendredi 14 décembre 2018

Object reference not set to an instance of an object. I have null a refference although I have used DBnull

I know whats null refference. But I have used a condition to avoid null refference which doesnt work. how should I use DBnull in this example?

           string selectQueryName = "SELECT name FROM tbl_attendanceMembers where memberCode=" + "'" + textBoxX1.Text + "'";
            var sqlcmdName = new SqlCommand(selectQueryName, sqlcon);
            var resultName = sqlcmdName.ExecuteScalar();
           **if (!DBNull.Value.Equals(resultName))**<-- this part
                    {

                        lbl_mmbrname.Text = resultName.ToString();
                        lbl_timestored.Text = t;
                        textBoxX1.Clear();


                    }

it says:

An unhandled exception of type 'System.NullReferenceException' occurred in project.exe

Additional information: Object reference not set to an instance of an object.

Aucun commentaire:

Enregistrer un commentaire