private void EditTheTable() { cnn.Open(); SQLiteCommand emir = new SQLiteCommand("", cnn); //SİLİNEN SÜTUN VAR MI bool _hasdele = false; bool _haschange = false; foreach (Models.TableField fld in _origfieldlist) { if (!_fieldlist.Contains(fld)) { _hasdele = true; } if (fld.FldIsUpdated) { _haschange = true; } } if (_hasdele || _haschange) { string _columnlist = "", _appendcolumn = ""; foreach (Models.TableField fld in _fieldlist) { _columnlist = _columnlist + "," + fld.FldName; _appendcolumn = _appendcolumn + "," + FXS.PrepareFieldString(fld); } _columnlist = _columnlist.Substring(1); _appendcolumn = _appendcolumn.Substring(1); emir.CommandText = "BEGIN TRANSACTION;" + "CREATE TEMPORARY TABLE t1_backup(" + _columnlist + ");" + "INSERT INTO t1_backup SELECT " + _columnlist + " FROM " + TableName + ";" + "DROP TABLE " + TableName + ";" + "CREATE TABLE " + TableName + " (" + _appendcolumn + ");" + "INSERT INTO " + TableName + " SELECT " + _columnlist + " FROM t1_backup;" + "DROP TABLE t1_backup;" + "COMMIT;"; try { emir.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //YENİ EKLENEN SÜTUN VAR MI foreach (Models.TableField fld in _fieldlist) { if (_origfieldlist.Contains(fld)) { continue; } try { emir.CommandText = "ALTER TABLE " + TableName + " ADD COLUMN " + FXS.PrepareFieldString(fld); emir.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } cnn.Close(); this.Close(); }
private void CreateTheTable() { string _tblCODE = "CREATE TABLE [" + Txt_TableName.Text + "] ("; foreach (Models.TableField fld in _fieldlist) { _tblCODE = _tblCODE + FXS.PrepareFieldString(fld) + ","; } _tblCODE = _tblCODE.Remove(_tblCODE.Length - 1) + ");"; try { SQLiteCommand emir = new SQLiteCommand(_tblCODE, cnn); cnn.Open(); emir.ExecuteNonQuery(); MainForm frmp = (MainForm)Application.OpenForms["MainForm"]; frmp.ShowDbStructure(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }