I am referring This Tutorial to store data in SQLite database. I am Trying to add another table to the database called "Schools". But it throws an Exception as follows saying No such table: Schools.
Classes
public class Contacts
{
//The Id property is marked as the Primary Key
[SQLite.PrimaryKey, SQLite.AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public string Age { get; set; }
public string Address { get; set; }
public string School { get; set; }
public string Gardient { get; set; }
public string PhoneNumber { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string CreationDate { get; set; }
public Contacts()
{
//empty constructor
}
public Contacts( string name, string age, string address, string school, string gardient, string phone_no, string latitude, string longitude)
{
Name = name;
Age = age;
Address = address;
School = school;
Gardient = gardient;
PhoneNumber = phone_no;
Latitude = latitude;
Longitude = longitude;
CreationDate = DateTime.Now.ToString();
}
}
public class Schools
{
//The Id property is marked as the Primary Key
[SQLite.PrimaryKey, SQLite.AutoIncrement]
public int Id { get; set; }
public string School { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string CreationDate { get; set; }
public Schools()
{
//empty constructor
}
public Schools( string school,string latitude, string longitude)
{
School = school;
Latitude = latitude;
Longitude = longitude;
CreationDate = DateTime.Now.ToString();
}
}
DatabaseHelperClass
public class DatabaseHelperClass
{
SQLiteConnection dbConn;
//Create Tabble
public async Task<bool> onCreate(string DB_PATH)
{
try
{
if (!CheckFileExists(DB_PATH).Result)
{
using (dbConn = new SQLiteConnection(DB_PATH))
{
dbConn.CreateTable<Schools>();
dbConn.CreateTable<Contacts>();
}
}
return true;
}
catch
{
return false;
}
}
public void createtable()
{
SQLite.SQLiteConnection db = new SQLite.SQLiteConnection(DB_PATH);
db.CreateTable<Schools>();
db.CreateTable<Contacts>();
}
private async Task<bool> CheckFileExists(string fileName)
{
try
{
var store = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
return true;
}
catch
{
return false;
}
}
I have found similar questions but not answered my issue :(
Aucun commentaire:
Enregistrer un commentaire