mercredi 22 avril 2015

Insert multiple rows in SQLite (WIndows phone 8)

I am creating a table named "Task" with four columns by taking a new class

 public sealed class Task
{

    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public DateTime CreationDate { get; set; }

}

To insert single row..i followed this..it working perfectly

private void Insert_Click(object sender, RoutedEventArgs e)    
    {
        using (var db = new SQLiteConnection(DB_PATH))
        {

            db.RunInTransaction(() =>
            {
                db.Insert(new Task() { Id = 1, FirstName = "Ken", LastName = d1[2], CreationDate = DateTime.Now });

          });

        }
    }

..but in my requirement ..i have to insert multiple rows at a time..i tried the following.

private void Insert_Click(object sender, RoutedEventArgs e)    //perfectly  working
    {
        using (var db = new SQLiteConnection(DB_PATH))
        {

            db.RunInTransaction(() =>
            {
                db.Insert(new Task() { Id = 1, FirstName = "Ken", LastName = d1[2], CreationDate = DateTime.Now });
                 db.Insert(new Task() { Id = 2, FirstName = "Justin", LastName = "Bieber", CreationDate = DateTime.Now });

                db.Insert(new Task() { Id = 3, FirstName = "king", LastName = "john", CreationDate = DateTime.Now });
            });

        }
    }

when i followed this,no error popped..but only first row is inserting.. no sign of second row details.. please help me in this regard..

Aucun commentaire:

Enregistrer un commentaire