(2, 'Janobe Sourcecode', 'Kabankalan City');
MySQL
libraries.
using MySql.Data.MySqlClient;
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;password=;database=tuts_dbperson;sslMode=none"); MySqlDataAdapter da; MySqlCommand cmd; DataTable dt; string sql;
private void RetrieveSingleResult(string sql) { try { con.Open(); int maxrow; cmd.Connection = con; cmd.CommandText = sql; da.SelectCommand = cmd; da.Fill(dt); maxrow = dt.Rows.Count; if(maxrow > 0) { textBox1.Text = dt.Rows[0].Field<string>("Fullname"); textBox2.Text = dt.Rows[0].Field<string>("Address"); } } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); da.Dispose(); } }
private void Form1_Load(object sender, EventArgs e) { sql = "SELECT * FROM `tblperson` WHERE PersonID=2"; RetrieveSingleResult(sql); }