Esempio n. 1
0
        /////////////ADO.NET

        /*public static string Insertar(string x)
         * {
         *  using (SQLiteConnection Conexion = DataBase.GetConnection())
         *  {
         *      try
         *      {
         *          string insert = string.Format("INSERT INTO Persona(Nombre) VALUES('{0}')", x);
         *
         *          SQLiteCommand Command = new SQLiteCommand(insert, Conexion);
         *          Command.ExecuteNonQuery();
         *          return "Persona Registrada";
         *      }
         *      catch (Exception e) { return e.Message; }
         *  }
         * }*/


        /*public static List<string> GetNames()
         * {
         *  List<string> Lista = new List<string>();
         *
         *  using (IDbConnection Conexion = DataBase.GetConnection())
         *  {
         *      try
         *      {
         *          SQLiteCommand Command = new SQLiteCommand("SELECT * FROM Persona", Conexion);
         *          SQLiteDataReader Reader = Command.ExecuteReader();
         *
         *          while (Reader.Read())
         *          {
         *              Lista.Add((string)Reader[1]);
         *          }
         *
         *          Reader.Close();
         *          return Lista;
         *      }
         *      catch (Exception ex)
         *      {
         *          return null;
         *      }
         *  }
         * }*/



        /////////DAPPER
        public static string Insertar(ePersona obj)
        {
            using (IDbConnection Conexion = DataBase.GetConnection())
            {
                try
                {
                    Conexion.Execute("INSERT INTO Persona(Nombre) VALUES(@Nombre)", obj);//El arroba permite usar esa descripcion para relacionarla con la propiedad respectiva del objeto pasado

                    return("Persona Registrada");
                }
                catch (Exception e) { return(e.Message); }
            }
        }
Esempio n. 2
0
 public string insertar(ePersona obj)
 {
     try
     {
         SqlConnection con    = db.conectaDB();
         string        insert = string.Format("insert into persona (codigo,nombre,edad) values('{0}','{1}',{2})", obj.Codigo, obj.Nombre, obj.Edad);
         SqlCommand    cmd    = new SqlCommand(insert, con);
         cmd.ExecuteNonQuery();
         return("insertó");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     finally
     {
         db.DesconectaDB();
     }
 }