Posted by : Sudhir Chekuri Sunday, 24 November 2013

C# code in windows phone 8 app with sqlite commands


 string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");


  private void BtnUpdate_OnClick(object sender, RoutedEventArgs e)
        {

 using (var db = new SQLiteConnection(dbPath))
            {
               db.DeleteAll<RechargePlansData>();
             db.RunInTransaction(() =>
             {
                 for (int i = 0; i < d.l.Count; i++)
                 {
                     db.Insert(new RechargePlansData() { statename = 1, networkname = 1, categoryname = 1, amount = "2000", talktime = "2200", validity = "1 months", descriptiondata = "voda description1" });
                 }     
             });       
}


 private void BtnUpdate_OnClick(object sender, RoutedEventArgs e)
        {
            using (var db = new SQLiteConnection(dbPath))
            {
                var existing = db.Query<Person>("select * from Person").FirstOrDefault();
                if (existing != null)
                {
                    existing.FirstName = "Denis";
                    db.RunInTransaction(() =>
                        {
                            db.Update(existing);
                        });
                }
            }
        }

        private void BtnDelete_OnClick(object sender, RoutedEventArgs e)
        {
            using (var db = new SQLiteConnection(dbPath))
            {
                var existing = db.Query<Person>("select * from Person").FirstOrDefault();
                if (existing != null)
                {
                    db.RunInTransaction(() =>
                    {
                        db.Delete(existing);
                    });
                }
            }
        }

C# code in RechargePlansData class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WP8Sqlite
{
    class RechargePlansData
    {
        [SQLite.PrimaryKey, SQLite.AutoIncrement]
        public int Id { get; set; }

        public int statename { get; set; }
        public int networkname { get; set; }
        public int categoryname { get; set; }
        public string amount { get; set; }
        public string talktime { get; set; }
        public string validity { get; set; }
        public string descriptiondata { get; set; }
        
    }
}


       

        

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

Blog Archive

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -