Exemple #1
0
 public void Insert(User user)
 {
     using (var statement = con.Prepare("INSERT INTO User (Name, Age, Salary, Phone) VALUES (?,?,?,?)"))
     {
         statement.Bind(1, user.Name);
         statement.Bind(2, user.Age);
         statement.Bind(3, user.Salary);
         statement.Bind(4, user.Phone);
         statement.Step();
     }
 }
Exemple #2
0
        public ObservableCollection<User> GetUsers()
        {
            ObservableCollection<User> users = new ObservableCollection<User>();

            using (var statement = con.Prepare("SELECT Id, Name, Age, Salary, Phone FROM User"))
            {
                while (statement.Step() == SQLiteResult.ROW)
                {
                    User user = new User();
                    user.Id = (long)statement[0];
                    user.Name = (string)statement[1];
                    user.Age = (long)statement[2];
                    user.Salary = (long)statement[3];
                    user.Phone = (string)statement[4];
                    users.Add(user);
                }
            }
            return users;
        }
Exemple #3
0
        public User GetUser(long id)
        {
            User user = null;

            using (var statement = con.Prepare("SELECT Id, Name, Age, Salary, Phone FROM User WHERE Id=?"))
            {
                statement.Bind(1, id);
                if (statement.Step() == SQLiteResult.ROW)
                {
                    user = new User();
                    user.Id = (long)statement[0];
                    user.Name = (string)statement[1];
                    user.Age = (long)statement[2];
                    user.Salary = (long)statement[3];
                    user.Phone = (string)statement[4];
                }
            }

            return user;
        }
Exemple #4
0
 public void Update(User user, long id)
 {
     using (var statement = con.Prepare("UPDATE User SET Name=?, Age=?, Salary=?, Phone=? WHERE Id=?"))
     {
         statement.Bind(1, user.Name);
         statement.Bind(2, user.Age);
         statement.Bind(3, user.Salary);
         statement.Bind(4, user.Phone);
         statement.Bind(5, id);
         statement.Step();
     }
 }