public void InserindoListaFabricantes(List<Fabricante> fabricantes) { using (var dbConn = new SQLiteConnection(DB_path)) { dbConn.DropTable<Fabricante>(); dbConn.Dispose(); dbConn.Close(); } foreach (Fabricante f in fabricantes) this.Inserindo(f); }
public void Dispose() { if (connection != null) { connection.Dispose(); // Liberar a conexão } }
public async Task <ObservableCollection <AccountsModel> > GetAllAccountsDB() { ObservableCollection <AccountsModel> _accounts_DB = new ObservableCollection <AccountsModel>(); try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { var AccountsDB = db.Table <AccountsModel>().Where(a => a.Name.Contains("a")); foreach (AccountsModel accountModel in AccountsDB) { _accounts_DB.Add(accountModel); } db.Commit(); db.Dispose(); db.Close(); //var line = new MessageDialog("Records Inserted"); //await line.ShowAsync(); } } catch (SQLiteException) { } return(_accounts_DB); }
private async Task AccountStore(ObservableCollection <AccountsModel> account) { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { foreach (AccountsModel accountM in Accounts) { var accountInDB = db.Find <AccountsModel>(accountM.Accountid); if (accountInDB != null) { db.Delete(accountM); } db.Insert(accountM); } db.Commit(); db.Dispose(); db.Close(); } } catch (SQLiteException) { } }
private async void deleteselected(object sender, RoutedEventArgs e) { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { db.Delete <person>(list1.SelectedItem.ToString()); var d = from x in db.Table <person>() select x; list1.Items.Clear(); foreach (var sd in d) { list1.Items.Add(sd.name.ToString()); //list1.Items.Add(sd.address.ToString()); //list1.Items.Add(sd.phone.ToString()); } db.Dispose(); db.Close(); } var line = new MessageDialog("Selected Item Deleted"); await line.ShowAsync(); } catch { } }
async void Login_Loaded() { try { await ApplicationData.Current.LocalFolder.CreateFileAsync("Shopping.db3"); var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Shopping.db3"); using (var db = new SQLite.SQLiteConnection(path)) { // Create the tables if they don't exist db.CreateTable<ShopLists>(); db.CreateTable<ShopAdmins>(); db.Commit(); db.Dispose(); db.Close(); } ServiceReference1.SoapServiceSoapClient sc=new SoapServiceSoapClient(); sc.AllCouponsCompleted += (a, b) => MessageBox.Show(b.Result); sc.AllCouponsAsync("hacking"); } catch (Exception ex) { FaultHandling(ex.StackTrace); } }
private void getFromDB(out Dictionary<string, string> dict, string Parent) { string dbPath = "test.sqlite"; var db = new SQLiteConnection(dbPath, true); var temp = db.Query<Tag>("SELECT * FROM Tag WHERE Parent='" + Parent + "'"); dict = new Dictionary<string, string>(); foreach (Tag el in temp) { dict.Add(el.Path, el.Name); } db.Dispose(); }
public void Dispose() { if (!disposed) { lock (queues) { disposed = true; queues.Remove(this.Name); store.Dispose(); GC.SuppressFinalize(this); } } }
/// <summary> /// Create Table for accout method /// </summary> /// private async Task <bool> createAccountTable() { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { // Create the tables if they don't exist db.CreateTable <AccountsModel>(); db.Commit(); db.Dispose(); db.Close(); } //var line = new MessageDialog("Table Created"); //await line.ShowAsync(); } catch (SQLiteException exLite) { throw new Exception(exLite.Message); } catch (Exception ex) { throw new Exception(ex.Message); } try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { AccountStore(Accounts); // Create the tables if they don't exist db.Commit(); db.Dispose(); db.Close(); //var line = new MessageDialog("Records Inserted"); //await line.ShowAsync(); } } catch (SQLiteException) { } return(true); }
private async void drop(object sender, RoutedEventArgs e) { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { db.DropTable <person>(); db.Dispose(); db.Close(); } var line = new MessageDialog("Table Dropped"); await line.ShowAsync(); } catch { } }
private void createtable() { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { // Create the tables if they don't exist db.CreateTable <person>(); db.Commit(); db.Dispose(); db.Close(); } } catch { } }
private async void insert(object sender, RoutedEventArgs e) { try { if (txt1.Text != "" && txt2.Text != "" && txt3.Text != "") { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { // Create the tables if they don't exist db.Insert(new person() { name = txt1.Text.ToString(), address = txt2.Text.ToString(), phone = Convert.ToDouble(txt3.Text.ToString()), } ); db.Commit(); db.Dispose(); db.Close(); var line = new MessageDialog("Records Inserted"); await line.ShowAsync(); } } else { throw new NullReferenceException("Enter The Data In Textboxes"); //var line = new MessageDialog("Enter The Data In Textboxes"); //await line.ShowAsync(); } } catch (SQLiteException) { } catch (NullReferenceException ex) { list1.Items.Add(ex.Message); } }
/// <summary> /// </summary> /// <param name="connection"></param> /// <returns></returns> private bool ReleaseConnection(SQLiteConnection connection) { if (_disposed) { connection?.Dispose(); return true; } lock (_lock) { _usedConnections.Remove(connection); if (!IsOpen(connection)) return false; _freeConnections.Enqueue(connection); _connectionRelease.Set(); } return true; }
private async void createtable(object sender, RoutedEventArgs e) { try { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { // Create the tables if they don't exist db.CreateTable <person>(); db.Commit(); db.Dispose(); db.Close(); } var line = new MessageDialog("Table Created"); await line.ShowAsync(); } catch { } }
}//DELETE CONTACT THAT I CHOSE //DELETE ALL public void DeleteAllContact() { using (var dbConn = new SQLiteConnection(App.DB_PATH)) { dbConn.DropTable<Contactos>(); dbConn.CreateTable<Contactos>(); dbConn.Dispose(); dbConn.Close(); } }
//Dispose public void Dispose() { conn.Dispose(); }
//~~~delete all activities public void DeleteActivities () { using (var dbConn = new SQLiteConnection(this.KreyosDBPath)) { //dbConn.RunInTransaction(() => // { dbConn.DropTable<Kreyos_User_Activities>(); dbConn.CreateTable<Kreyos_User_Activities>(); dbConn.Dispose(); dbConn.Close(); //}); } }
//Delete all contactlist or delete Contacts table public void DeleteAllContact() { using (var dbConn = new SQLiteConnection(App.DB_PATH)) { //dbConn.RunInTransaction(() => // { dbConn.DropTable<GhiChu>(); dbConn.CreateTable<GhiChu>(); dbConn.Dispose(); dbConn.Close(); //}); } }
static void Main(string[] args) { string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); // SQLiteConnection.CreateFile(exePath + DB_PATH); // SQLite Verbinung zu Datenbank öffnen SQLiteConnection connection = new SQLiteConnection(SQL_DATA_SOURCE + exePath + DB_PATH); connection.Open(); SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = "DROP TABLE IF EXISTS Attribut"; command.ExecuteNonQuery(); // Tabelle erstellen command.CommandText = "CREATE TABLE IF NOT EXISTS Attribut (id INTEGER PRIMARY KEY AUTOINCREMENT)"; command.ExecuteNonQuery(); // Der Tabelle ein Paar SPalten hinzufügen command.CommandText = "ALTER TABLE Attribut ADD COLUMN Attribut1 TEXT"; command.ExecuteNonQuery(); command.CommandText = "ALTER TABLE Attribut ADD COLUMN Attribut2 TEXT"; command.ExecuteNonQuery(); // Eintrag erzeugen for (int i = 1; i <= 15; i++) { command.CommandText = "INSERT INTO Attribut VALUES(NULL, 'eintrag" + i + "1', 'Eintrag" + i + "2')"; command.ExecuteNonQuery(); } command.CommandText = "SELECT Attribut1, Attribut2 FROM Attribut"; using (SQLiteDataReader reader = command.ExecuteReader()) { Console.WriteLine(command.CommandText); while (reader.Read()) { for (int field = 0; field < reader.FieldCount; field++) { Console.Write(reader[field] + " "); } Console.Write("\n"); } } command.CommandText = "SELECT * FROM Attribut WHERE id = 1 or id = 3"; using (SQLiteDataReader reader = command.ExecuteReader()) { Console.WriteLine(command.CommandText); while (reader.Read()) { for (int field = 0; field < reader.FieldCount; field++) { Console.Write(reader[field] + " "); } Console.Write("\n"); } } command.Dispose(); // zum Schluss wieder schließen connection.Close(); connection.Dispose(); }
void CreateDatabase(string dbPath) { #if __ANDROID__ var s = Application.Context.Assets.Open(originalDBLocation); var writeStream = new FileStream(dbPath, FileMode.OpenOrCreate, FileAccess.Write); ReadWriteStream(s, writeStream); writeStream.Close(); #elif __IOS__ var appDir = NSBundle.MainBundle.ResourcePath; var originalLocation = Path.Combine (appDir, originalDBLocation); File.Copy (originalLocation, dbPath); #endif //copies profiles and selected eigenschappen from the old database to the new one if (File.Exists(OldDatabasePath)) { SQLiteConnection oldDb = new SQLiteConnection(OldDatabasePath); SQLiteConnection newDB = new SQLiteConnection(dbPath); var oldProfielen = oldDb.Query<Profiel>("SELECT * FROM profiel"); var oldEigenschappenSer = oldDb.Query<Profiel_eigenschappen>("SELECT * FROM profiel_eigenschappen"); foreach(Profiel p in oldProfielen) newDB.Execute("INSERT INTO profiel (name, nid) values (?, ?)", p.name, p.nid); foreach (Profiel_eigenschappen pe in oldEigenschappenSer) newDB.Execute("INSERT INTO profiel_eigenschappen (name, eigenschappen_ser) values (?, ?)", pe.name, pe.eigenschappen_ser); oldDb.Dispose(); newDB.Dispose(); File.Delete(OldDatabasePath); } }