Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Author: Ajay Kumar */
- /* You must design your form as in the shown image */
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace SimpleBindingRun
- {
- public partial class Form1 : Form
- {
- static string constr = "server=localhost;user=root;database=world;port=3306;password=AjayKumarB;";
- /*Replace the connection parameters according to your machines configuration */
- MySqlConnection conn = new MySqlConnection(constr);
- MySqlDataAdapter adap;
- DataSet ds = new DataSet();
- BindingSource bs = new BindingSource();
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string qry = "SELECT * FROM CITY";
- adap = new MySqlDataAdapter(qry, conn);
- MySqlCommandBuilder cb = new MySqlCommandBuilder(adap);
- adap.Fill(ds, "City");
- bs.DataSource = ds;
- bs.DataMember = "City";
- id_text.DataBindings.Add("Text", bs, "ID");
- name_text.DataBindings.Add("Text", bs, "Name");
- reg_text.DataBindings.Add("Text", bs, "CountryCode");
- dst_text.DataBindings.Add("Text", bs, "District");
- pop_text.DataBindings.Add("Text", bs, "Population");
- BindingNavigator bn = new BindingNavigator(true);
- bn.BindingSource = bs;
- this.Controls.Add(bn);
- dataGridView1.DataSource = ds;
- dataGridView1.DataMember = "City";
- }
- private void button2_Click(object sender, EventArgs e)
- {
- bs.MovePrevious();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- bs.MoveNext();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- bs.MoveFirst();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- bs.MoveLast();
- }
- private void button6_Click(object sender, EventArgs e)
- {
- bs.Position = Convert.ToInt32(textBox1.Text)-1;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- bs.AddNew();
- }
- private void button8_Click(object sender, EventArgs e)
- {
- bs.RemoveCurrent();
- }
- private void button9_Click(object sender, EventArgs e)
- {
- adap.Update(ds,"City");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement