Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            SupplierView sv = new SupplierView();

            sv.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            String name = sname.Text;
            String pho  = phone.Text;

            if (name == "" || pho == "")
            {
                MessageBox.Show("Every Field are Required");
            }
            else
            {
                string          connectionString   = "datasource=127.0.0.1;port=3306;username=root;password=;database=debuggeddb;";
                MySqlConnection databaseConnection = new MySqlConnection(connectionString);
                try
                {
                    databaseConnection.Open();
                    MySqlCommand comm = databaseConnection.CreateCommand();
                    comm.CommandText = "INSERT INTO suppliertable (`SupplierName`,`PhoneNo`) VALUES (@sn,@ph);";
                    comm.Parameters.AddWithValue("@sn", name);
                    comm.Parameters.AddWithValue("@ph", pho);
                    comm.ExecuteNonQuery();
                    databaseConnection.Close();
                    //clear the text
                    sname.Text = "";
                    phone.Text = "";
                    //message
                    MessageBox.Show("Data Has been successfully inserted");
                    this.Hide();
                    SupplierView sv = new SupplierView();
                    sv.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }