public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; SettingDatabase = new DatabaseSetting { Server = config.Server, Database = config.Database, UserName = config.User, Password = config.Password, Port = config.Port.ToString() }; this.FolderPath.Text = config.Path; this.Poco.Checked = true; this.Modern.Checked = true; this.Header.Text = @"using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; "; this.constr = string.Format("Server={0};database={1};UID={2};password={3};Port={4};CharSet=utf8;Persist Security Info=True", SettingDatabase.Server, SettingDatabase.Database, SettingDatabase.UserName, SettingDatabase.Password, SettingDatabase.Port); this.commandText = string.Format( @"SELECT TABLE_SCHEMA, DATA_TYPE, COLUMN_TYPE, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS where `columns`.`TABLE_Schema`='{0}' group by table_name", SettingDatabase.Database); //using (var db = new OcphDbContext(constr)) //{ // var cmd =db.CreateCommand(); // cmd.CommandType = CommandType.Text; // cmd.CommandText = "Select * from anggota;"; // var dr = cmd.ExecuteReader(); // var mapping = MappingProperties<anggota>.MappingTable(dr); //} }
private void button2_Click(object sender, EventArgs e) { this.Model = new DatabaseSetting { Database = this.DatabaseTxt.Text, Password = PasswordTxt.Text, Port = porttxt.Text, Server = Servertxt.Text, UserName = UserTxt.Text }; var constr = string.Format("Server={0};database={1};UID={2};password={3};Port={4};CharSet=utf8;Persist Security Info=True", Model.Server, Model.Database, Model.UserName, Model.Password, Model.Port); using (var db = new ContextTest(constr)) { try { db.Open(); MessageBox.Show("Connection Is Ok"); db.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }