Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CLO s = new CLO();
                s.set_Name(text1.Text);
                s.set_Data_Created(dateTimePicker3.Value);
                s.set_Data_Updated(dateTimePicker4.Value);

                if ((s.get_Name() == null || s.get_Name() == "") || (s.get_Data_Created() == null) || (s.get_Data_Updated() == null))
                {
                    MessageBox.Show("Submssion is not allowed with null values");
                }
                else
                {
                    string        constr = "Data Source=DESKTOP-GP94IEM\\SQLEXPRESS;Initial Catalog=Projectb;Integrated Security=True";
                    SqlConnection c      = new SqlConnection(constr);
                    c.Open();
                    int f   = dataGridView1.CurrentCell.RowIndex;
                    int id4 = (int)(dataGridView1.Rows[f].Cells["Id"].Value);
                    //MessageBox.Show("Updating this entry"

                    string s1 = string.Format("UPDATE clo SET Name=@Name, DateCreated=@DateCreated,DateUpdated=@DateUpdated where Id=@Id");

                    //values('" + s.get_FirstName() + "',  '" + s.get_LastName() + "','" + s.get_Contact() + "','" + s.get_Email() + "','" + s.get_Registration_No() + "','" + id + "')");

                    //string s1 = string.Format("INSERT INTO Student(FirstName,LastName,Contact,Email,RegistrationNumber,Status) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", s.get_FirstName(), s.get_LastName(), s.get_Contact(), s.get_Email(), s.get_Registration_No(), id);
                    SqlCommand a2 = new SqlCommand(s1, c);
                    //GetExample(a2, p.ToArray());

                    a2.Parameters.Add(new SqlParameter("Id", id4));

                    a2.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar));
                    a2.Parameters["@Name"].Value = s.get_Name();
                    a2.Parameters.Add(new SqlParameter("@DateCreated", SqlDbType.DateTime));
                    a2.Parameters["@DateCreated"].Value = s.get_Data_Created();
                    a2.Parameters.Add(new SqlParameter("@DateUpdated", SqlDbType.DateTime));
                    a2.Parameters["@DateUpdated"].Value = s.get_Data_Updated();

                    int rows = a2.ExecuteNonQuery();
                    if (rows != 0)
                    {
                        MessageBox.Show("CLO Updated");
                        c.Close();
                        panel1.Hide();
                        this.Close();
                        Manage_Clo j = new Manage_Clo();
                        j.Show();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CLO s = new CLO();
                s.set_Name(Name.Text);
                s.set_Data_Created(dateTimePicker1.Value);
                s.set_Data_Updated(dateTimePicker2.Value);
                if ((Name.Text == "") || (dateTimePicker1.Value == null) || (dateTimePicker2.Value == null))
                {
                    MessageBox.Show("Submssion is not allowed with null values");
                }
                else if ((s.get_Name() == "" || (s.get_Name() == null)) || (s.get_Data_Created() == null) || (s.get_Data_Updated() == null))
                {
                    MessageBox.Show("Invalid Data Entered!!");
                }
                else
                {
                    string        constr = "Data Source=DESKTOP-GP94IEM\\SQLEXPRESS;Initial Catalog=Projectb;Integrated Security=True";
                    SqlConnection c      = new SqlConnection(constr);
                    c.Open();

                    string     s2   = string.Format("INSERT INTO Clo(Name,DateCreated,DateUpdated) values('" + s.get_Name() + "','" + s.get_Data_Created() + "','" + s.get_Data_Updated() + "')");
                    SqlCommand a2   = new SqlCommand(s2, c);
                    int        rows = a2.ExecuteNonQuery();
                    if (rows != 0)
                    {
                        MessageBox.Show("CLO Added");
                        this.Close();
                        Manage_Clo h = new Manage_Clo();
                        h.Show();
                    }
                    c.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }