database - How to use SQLite.Net to create, insert and draw data in Xamarin.Android? -
i new xamarin , android development. making timetable app , have no idea of how create database using sqlite.net. there possibly documentation of commands can used , thorough description somewhere? because find stuffs related java, ios, , other stuffs.
in app, need create, access, insert, modify , draw links between database, unsure of how any.
thanks
using sqlite.net easy in xamarin android/ios/forms. add nuget package "sqlite-net" intp project. add 2 files, sqlite.cs , sqliteasync.cs in root folder. uses orm hance crud functions can used easily.
here few links xamarin understand concepts better.
https://developer.xamarin.com/recipes/android/data/databases/sqlite/
https://developer.xamarin.com/recipes/ios/data/sqlite/
https://developer.xamarin.com/guides/xamarin-forms/working-with/databases/
https://developer.xamarin.com/recipes/ios/data/sqlite/create_a_database_with_sqlitenet/
edit 1:
include sqlite-net nuget package frank krueger in application.
create file keeping databse related functions. instance dboperations.cs
public class dboperations { public string sqlitedbpath { get; private set; } public dboperations() { string databasepath = system.io.path.combine(system.environment.getfolderpath(environment.specialfolder.personal), dbconstants.database_path); _sqlitedbfilepath = system.io.path.combine(databasepath, dbconstants.database_name); sqlitedbpath = databasepath; system.io.directory.createdirectory(sqlitedbpath); //create database in set path sqlite.sqlite3.config(sqlite.sqlite3.configoption.serialized); sqliteconnection sqliteconnection = new sqliteconnection(_sqlitedbfilepath); sqliteconnection.close(); createtables(); } private void createtables() { sqliteconnection sqliteconnection = new sqliteconnection(_sqlitedbfilepath); sqliteconnection.createtable<user>(); sqliteconnection.close(); } }
this snippet create database , table object named user in db.
to perform crud operations write
sqliteconnection con = new sqliteconnection(_sqlitedbfilepath); con.insert(userobject); //insert con.delete(userobject); //delete con.deleteall<>(); //delete rows in table user con.update(userobject); //update list<user> userlist = con.query<user>("select * user"); //select
hope helps you.
Comments
Post a Comment