I need to extract a single value from the database to assign it to a variable int
and then use it, but I can not get it.
Try the syntax of the query and return the value I need, the problem is that I can not assign it, I return the following error on line 5:
System.InvalidOperationException: 'Error de lectura porque no hay datos.'
con.Open();
string str = "SELECT TOP 1 Id FROM productosencola ORDER BY Id DESC;";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader rdr = cmd.ExecuteReader();
int idmax = int.Parse(rdr.GetValue(0).ToString());