Instate of this
if (reader1.HasRows)
{
device = reader1.GetValue(0).ToString();
}
Write this
if (reader1.HasRows)
{
if(reader1.Read())
{
device = reader1.GetValue(0).ToString();
}
}
and you can remove this line(delete this line)
command.ExecuteNonQuery();