G_ID is an integer column in Groups table. I want the maximum value of it. When I trace below code I receive the error I've mentioned in code. Reader.HasRows equals true during debugging. So why it says "no data is present"
SqlConnection sqlc= new SqlConnection("data source=. ; database=LDatabase; integrated security=true");
SqlCommand cmd= new SqlCommand("select MAX(G_ID) as MAXID from Groups", sqlc);
sqlc.Open();
SqlDataReader Reader= cmd.ExecuteReader();
int MaxID = 0;
if (Reader.HasRows)
{
MaxID = Convert.ToInt32(Reader["MAXID"].ToString());// Here I receive this error: System.InvalidOperationException: Invalid attempt to read when no data is present.
MaxID += 1;
}
Reader.Read()before you can access the columns ...