void Malestudent() { using (DataTable dt2 = LookupUser2(txtRegNumber.Text)) { if (dt2.Rows.Count == 0) { messagebox.show(" profile is not updated") return; } else { // renaming the items retreived to be passed to another method string R_Number = Convert.ToString(dt2.Rows[0]["RegNumber"]); string strname = Convert.ToString(dt2.Rows[0]["FullName"]); string strsx = Convert.ToString(dt2.Rows[0]["Sex"]); string strlevel = Convert.ToString(dt2.Rows[0]["Level"]); string strdpt = Convert.ToString(dt2.Rows[0]["Department"]); string strfact = Convert.ToString(dt2.Rows[0]["Faculty"]); string strsess = Convert.ToString(dt2.Rows[0]["Session"]); . . . }private static DataTable LookupUser2(string RegNumber) { // where i am looking into dbs in search of where RegNumber exist. // ERROR COMES FROM HERE string connStr = ConfigurationManager.ConnectionStrings["SchooldataConnectionString1"].ConnectionString; const string query = "SELECT FullName,RegNumber,Sex,Level,Department,Faculty,Session FROM StudentData(NOLOCK) Where RegNumber = @RegNumber"; DataTable result2 = new DataTable(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@RegNumber", SqlDbType.VarChar).Value = RegNumber; using (SqlDataReader dr = cmd.ExecuteReader()) { result2.Load(dr); } } } return result2; }