/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public TableViewModel(string name, string definition, SQLiteConnection conn) { Name = name; this.definition = definition; this.conn = conn; adapter = new SQLiteDataAdapter("select * from " + Name, conn); adapter.Fill(Table); try { SQLiteCommand cmd = new SQLiteCommand("select * from " + Name, conn); using (var reader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly)) { var columnSchemaTable = reader.GetSchemaTable(); foreach (DataRow dr in columnSchemaTable.Rows) { FieldViewModel fieldInfo = new FieldViewModel() { Name = dr["ColumnName"].ToString(), Type = dr["DataTypeName"].ToString(), IsPrimaryKey = (bool)dr["IsKey"], IsUnique = (bool)dr["IsUnique"], AllowDBNull = (bool)dr["AllowDBNull"], IsAutoIncrement = (bool)dr["IsAutoIncrement"] }; FieldsInfo.Add(fieldInfo); } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public TableViewModel(string name,string definition,SQLiteConnection conn) { Name = name; this.definition = definition; this.conn = conn; adapter = new SQLiteDataAdapter("select * from " + Name, conn); adapter.Fill(Table); try { SQLiteCommand cmd = new SQLiteCommand("select * from " + Name, conn); using (var reader = cmd.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly)) { var columnSchemaTable = reader.GetSchemaTable(); foreach (DataRow dr in columnSchemaTable.Rows) { FieldViewModel fieldInfo = new FieldViewModel() { Name = dr["ColumnName"].ToString(), Type = dr["DataTypeName"].ToString(), IsPrimaryKey = (bool)dr["IsKey"], IsUnique = (bool)dr["IsUnique"], AllowDBNull = (bool)dr["AllowDBNull"], IsAutoIncrement = (bool)dr["IsAutoIncrement"] }; FieldsInfo.Add(fieldInfo); } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }