Пример #1
0
 private void addBtn_Click(object sender, EventArgs e)
 {
     if (textBox1.Text != "" && textBox2.Text != "" && comboBox1.Text != "")
     {
         db.Open();
         try
         {
             string     selid = crsf.dgv.CurrentRow.Cells["Марка-Модель"].Value.ToString();
             SqlCommand cmd   = db.CreateCommand();
             cmd.CommandType = CommandType.Text;
             cmd.CommandText = "UPDATE Cars SET NameAuto=N'" + textBox1.Text + "',Date=N'" + numericUpDown1.Value + "',GosNum=N'" + textBox2.Text + "',Klass=N'" + comboBox1.Text + "',NameRider=N'" + comboBox2.Text + "'  WHERE NameAuto = N'" + selid + "'";
             cmd.ExecuteNonQuery();
         }
         finally
         {
             db.Close();
         }
         crsf.CarsFrm_Load(sender, e);
         this.Close();
     }
     else
     {
         MessageBox.Show("Некоторые поля остались пустыми, заполните их!");
     }
 }
Пример #2
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && comboBox1.Text != "" && comboBox2.Text != "")
            {
                db.Open();

                string         query = "INSERT INTO Cars (NameAuto,Date,GosNum,Klass,NameRider) VALUES(N'" + textBox1.Text + "','" + numericUpDown1.Value + "',N'" + textBox2.Text + "',N'" + comboBox1.Text + "',N'" + comboBox2.Text.ToString() + "')";
                SqlDataAdapter sna   = new SqlDataAdapter(query, db);
                sna.SelectCommand.ExecuteNonQuery();



                db.Close();
                frm.CarsFrm_Load(sender, e);

                this.Close();
            }
            else
            {
                MessageBox.Show("Пожалуйста заполните поля!");
            }
        }