Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=DELL-PC\\SQLEXPRESS;Initial Catalog=NGOIdatabase;Integrated Security=True");

            conn.Open();
            try {
                SqlCommand comd = conn.CreateCommand();
                comd.CommandType = CommandType.Text;
                DateTime d = Convert.ToDateTime(dateTimePicker1.Text);
                if (textBox1.Text == "")
                {
                    //MessageBox.Show("I will create new");
                    comd.CommandText = "INSERT INTO Customers (Cus_name, Cus_phone, Date_created, Cus_address) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + d.Year + "-" + d.Month + "-" + d.Day + "','" + textBox5.Text + "')";
                }
                else
                {
                    //MessageBox.Show("I will update");
                    comd.CommandText = "UPDATE Customers SET Cus_name='" + textBox2.Text + "',Cus_Phone='" + textBox3.Text + "',Cus_address='" + textBox5.Text + "',date_created='" + d.Year + "-" + d.Month + "-" + d.Day + "' where Cus_id=" + textBox1.Text;
                }
                comd.ExecuteNonQuery();

                dataGridView1.DataSource = cdb.selectall();
                conn.Close();
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
            reset_layout();
            this.Close();
            Customer a = new Customer();

            a.Show();
        }
Example #2
0
        private void Customer_Load(object sender, EventArgs e)
        {
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;
            TopMost         = false;
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 10);
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            customerdb cdb = new customerdb();

            dataGridView1.DataSource = cdb.selectall();
        }