Forum Xamarin Xamarin.Forms

What are the ways to insert large number of static data (say 1000 rows) into a table using sqllite?

abbasferrariabbasferrari INMember
edited September 2016 in Xamarin.Forms

namespace Cgpa
{
public class CgpaDatabase
{
static object locker = new object();

    SQLiteConnection database;

    public CgpaDatabase()
    {
        database = DependencyService.Get<ISQLite>().GetConnection();
        database.CreateTable<creditTable>();

    }
    public IEnumerable GetItems ()
    {
        lock (locker)
        {
            return (from i in database.Table<creditTable>() select i).ToList();     
         }

    }

    public int saveCredit(creditTable course)
    {
        lock (locker)
        {
            if(course.ID != 0)
            {
                database.Update(course);
                return course.ID;
            }
            else
            {
                return database.Insert(course);
            }

        }
    }
    public IEnumerable getCredits(string courseCode)
    {
        lock (locker)
        {
            return database.Query<creditTable>("SELECT * FROM [creditTable] WHERE [courseCode] LIKE '?'",courseCode).ToList(); //courseCode in form of 12XW25
        }
    }
    public int deleteItem(int id)
    {
        lock (locker)
        {
            return database.Delete<creditTable>(id);
        }
    }
}

}
After adding those data into my table i should not get populated data again while i compile the code , please give me some efficient way to insert huge data into my table.
Thanks :)

Best Answers

Answers

  • MabroukMabrouk USMember ✭✭✭

    Hi @abbasferrari , can you explain more what you need?

  • @Mabrouk said:
    Hi @abbasferrari , can you explain more what you need?

    Hi Mabrouk , I want to create an app which will access the local database for its manipulations so , i am looking for a way to insert those data into the local database at start.

    when i inserted data into the database its getting inserted each and every time when i run the code. Thats why i'm asking a way to avoid the repeated insertion into the database at run time with an efficient way

  • I'll check it out
    Thank you :)@Mabrouk

Sign In or Register to comment.