namespace App014 { public partial class Form1 : Form { private MySqlConnection conn; private DataTable data; private MySqlDataAdapter da; private MySqlCommandBuilder cb; public Form1() { InitializeComponent(); ConnectDB(); } private void ConnectDB() { if (conn != null) conn.Close(); string connStr = "server=localhost;user id=root; password=xxxxx; database=eTest"; try { conn = new MySqlConnection(connStr); conn.Open(); data = new DataTable(); da = new MySqlDataAdapter("SELECT code,name FROM USERMASTER", conn); cb = new MySqlCommandBuilder(da); da.Fill(data); lstUser.DataSource = data; lstUser.DisplayMember = "name"; lstUser.ValueMember = "code"; txtCode.DataBindings.Add(new System.Windows.Forms.Binding("Text", data, "code")); txtName.DataBindings.Add(new System.Windows.Forms.Binding("Text", data, "name")); } catch (MySqlException ex) { MessageBox.Show("Error connecting to the server: " + ex.Message); } } private void UpdateData() { DataTable changes = data.GetChanges(); if (changes != null) { da.Update(changes); data.AcceptChanges(); } else { MessageBox.Show("No Changes found"); } } private void btnSave_Click(object sender, EventArgs e) { UpdateData(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)