コード例 #1
0
        private void BunifuFlatButton1_Click(object sender, EventArgs e)
        {
            string ext = Path.GetExtension(filepath);

            if (string.IsNullOrEmpty(bunifuMaterialTextbox1.Text.Trim()) && string.IsNullOrEmpty(bunifuMaterialTextbox2.Text.Trim()) && string.IsNullOrEmpty(bunifuMaterialTextbox3.Text.Trim()))
            {
                MessageBox.Show("You must provide all fields", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                DBconnect dBconnect = new DBconnect();
                void insert()
                {
                    dBconnect.Insert($"INSERT INTO customers (CustomerName,Mobile,Address,Picture) VALUES('{bunifuMaterialTextbox1.Text}','{bunifuMaterialTextbox2.Text}','{bunifuMaterialTextbox3.Text}','{pictureBox1.Tag}')");
                    dBconnect.Select("SELECT * FROM  customers", dataGridView1);
                    dataGridView1.Update();
                }

                if (pictureBox1.Image == null)
                {
                    insert();
                }
                else
                {
                    File.Copy(filepath, imagesPath + bunifuMaterialTextbox2.Text + ext, true);
                    pictureBox1.Tag = bunifuMaterialTextbox2.Text + ext;
                    insert();
                }
            }

            dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
            dataGridView1.FirstDisplayedScrollingRowIndex             = dataGridView1.Rows.Count - 1;
        }
コード例 #2
0
        private void btn_add_Click(object sender, EventArgs e)
        {
            string Name      = textBox1.Text;
            string RegNumber = textBox2.Text;

            DBconnect db = new DBconnect();

            db.Insert("INSERT INTO students (Name, RegistrationNumber) VALUES('" + Name + "', '" + RegNumber + "')");
        }