Beispiel #1
0
        public GuildaModels ObterGuilda(long id)
        {
            SqlConnection conexao = new SqlConnection();
            SqlCommand    command = new SqlCommand();

            conexao.ConnectionString = ConfigurationManager.ConnectionStrings["DB_SW"].ToString();
            StringBuilder select = new StringBuilder();

            select.AppendLine("select Id,Nome from");
            select.AppendLine("DB_SW.dbo.Guilda ");
            select.AppendLine("where id = @id ");

            command.CommandText = select.ToString();
            command.CommandType = System.Data.CommandType.Text;

            command.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int));
            command.Parameters["@id"].Value = id;

            try
            {
                GuildaModels objGuilda = new GuildaModels();

                conexao.Open();

                command.Connection = conexao;
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    objGuilda      = new GuildaModels();
                    objGuilda.Id   = long.Parse(reader["Id"].ToString());
                    objGuilda.Nome = reader["Nome"].ToString();
                }

                conexao.Close();
                conexao.Dispose();

                return(objGuilda);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public List <GuildaModels> ListarGuildas()
        {
            SqlConnection conexao = new SqlConnection();
            SqlCommand    command = new SqlCommand();

            conexao.ConnectionString = ConfigurationManager.ConnectionStrings["DB_SW"].ToString();
            StringBuilder select = new StringBuilder();

            select.AppendLine("select Id,Nome from");
            select.AppendLine("DB_SW.dbo.Guilda ");

            command.CommandText = select.ToString();
            command.CommandType = System.Data.CommandType.Text;

            try
            {
                List <GuildaModels> lstGuilda = new List <GuildaModels>();

                conexao.Open();

                command.Connection = conexao;
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    GuildaModels objGuilda = new GuildaModels();
                    objGuilda      = new GuildaModels();
                    objGuilda.Id   = long.Parse(reader["Id"].ToString());
                    objGuilda.Nome = reader["Nome"].ToString();

                    lstGuilda.Add(objGuilda);
                }

                conexao.Close();
                conexao.Dispose();

                return(lstGuilda);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }