Error in obj.staffs RRS feed

  • Question

  • User1861182577 posted

            int staffID;
            private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
                       if (e.RowIndex != -1 && e.ColumnIndex != -1)
                    DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                    staffID = Convert.ToInt32(row.Cells["userIDGV"].Value.ToString());
                    nameTxt.Text = row.Cells["nameGV"].Value.ToString();
                    usernameTxt.Text = row.Cells["usernameGV"].Value.ToString();
                    passTxt.Text = row.Cells["passwordGV"].Value.ToString();
                    cpassTxt.Text = row.Cells["passwordGv"].Value.ToString();
                    p1Txt.Text = row.Cells["phone1GV"].Value.ToString();
                    p2Txt.Text = row.Cells["Phone2Gv"].Value.ToString();
                    roleDD.SelectedItem = row.Cells["RoleGV"].Value.ToString();
                    statusDD.SelectedItem = row.Cells["Status"].Value.ToString();

                    var im = (from x in obj.staffs where x.st_id == staffID select x.st_image).First();
                    if (im == null)

    Tuesday, April 27, 2021 6:12 AM

All replies

  • User753101303 posted


    For now the code doesn't show how obj is declared or initialized? It's likely best to start by looking at which error message your have rather than to guess from the code.

    Do you have a compile time error or a NullReferenceException ?

    Edit: in  short it seems that obj is not declared or if declared not initialized to a non null value. Could be still any other issue (a wrong connection to the db etc..). The purpose of errror messages is to tell you which bad thing happens and ti would be best to always start from the error message.

    Tuesday, April 27, 2021 7:18 AM