SqlCommand cmd = new SqlCommand("SELECT MAX(Register_ID) AS Register_ID FROM EnrollTbl", con);
SqlDataReader reader;
con.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
RegisterID.Text = (Convert.ToInt32(reader["Register_ID"]) + 1).ToString();
}
}
else
{
RegisterID.Text = "10000";
}
reader.Close();
It says Object cannot be cast from DBNull to other types. I believe i'm not doing the sqldatareader right. could someone correct my code?