예제 #1
0
        public List <Game_Grid_BD> Pesquisar_Game()
        {
            string sqlA = "Select * FROM TB_GAME";

            using (var conn = new SqlConnection(@"data source=.\SQLEXPRESS;initial catalog=BD_GAME;integrated security=True;MultipleActiveResultSets=True"))
            {
                var cmd = new SqlCommand(sqlA, conn);
                List <Game_Grid_BD> dados = new List <Game_Grid_BD>();
                Game_Grid_BD        p     = null;
                try
                {
                    conn.Open();
                    using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (reader.Read())
                        {
                            p           = new Game_Grid_BD();
                            p.Codigo    = Convert.ToInt16(reader["CD_GAME"]);
                            p.Nome_Game = reader["NM_GAME"].ToString();
                            dados.Add(p);
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
                return(dados);
            }
        }
예제 #2
0
 public Game_Grid_BD Pesquisar_pelo_Codigo(int pCodigo)
 {
     using (var conn = new SqlConnection(@"data source=DESKTOP-OUCTPF0\SQLEXPRESS;initial catalog=BD_GAME;integrated security=True"))
     {
         string     sql = "Select * FROM TB_GAME WHERE CD_GAME=@cod";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@cod", pCodigo);
         Game_Grid_BD oGame = null;
         try
         {
             conn.Open();
             using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
             {
                 if (reader.HasRows)
                 {
                     if (reader.Read())
                     {
                         oGame           = new Game_Grid_BD();
                         oGame.Codigo    = (int)reader["CD_GAME"];
                         oGame.Nome_Game = reader["NM_GAME"].ToString();
                     }
                 }
             }
         }
         finally
         {
             conn.Close();
         }
         return(oGame);
     }
 }
예제 #3
0
 public void Alterar(Game_Grid_BD pGame)
 {
     using (var conn = new SqlConnection(@"data source=.\SQLEXPRESS;initial catalog=BD_TESTE;integrated security=True;MultipleActiveResultSets=True"))
     {
         string     sql = "UPDATE TB_GAME SET NM_GAME=@nome Where CD_GAME=@cod";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@cod", pGame.Codigo);
         cmd.Parameters.AddWithValue("@nome", pGame.Nome_Game);
         try
         {
             conn.Open();
             cmd.ExecuteNonQuery();
         }
         finally
         {
             conn.Close();
         }
     }
 }
예제 #4
0
 public void Inserir(Game_Grid_BD pGame)
 {
     using (var conn = new SqlConnection(@"data source=.\SQLEXPRESS;initial catalog=BD_GAME;integrated security=True;MultipleActiveResultSets=True"))
     {
         string     sql = "INSERT INTO TB_GAME (NM_GAME, TOTAL_MORTE) VALUES (@nome, @total)";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@nome", pGame.Nome_Game);
         cmd.Parameters.AddWithValue("@total", pGame.Total_Morte);
         try
         {
             conn.Open();
             cmd.ExecuteNonQuery();
         }
         finally
         {
             conn.Close();
         }
     }
 }