I am programming in C# and I keep getting an error for my string variable result.
When I hover over the line return result it says use of unassigned local variable.
Do I have to assign result a value before I use it? How come i do not get the same error for SqlDataReader reader?
string searchbyLastName(string lastname) { string result; SqlDataReader reader; try { reader = myCommand.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { if (reader["LastName"].ToString() == lastname) { result = reader.GetString(0); break; } } return result; } else return "No results found"; } catch (Exception) { return("Database Error"); } }