string var = "";
SqlConnection con = new SqlConnection(Banco._strCon);
string sql = "select max(end_id) from endereco";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
var = (dr["max"]).ToString();
dr.Close();
con.Close();
return var;
I need this value of max
, but I do not know what to spend within [""]
. If I leave like this, the following error appears:
dr ["max"] 'dr ["max"]' threw an exception of type 'System.IndexOutOfRangeException' object {System.IndexOutOfRangeException}