Esempio n. 1
0
        private void SecretaryMessage_Load(object sender, EventArgs e)
        {
            SqlConnection conDataBase = new SqlConnection(constring);
            SqlCommand    cmdDataBase = new SqlCommand("select * from SecMes", conDataBase);

            try
            {
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmdDataBase;
                DataTable dt = new DataTable();
                sda.Fill(dt);

                DataView dv = new DataView(dt);
                dv.RowFilter = string.Format("Receiver Like '%{0}%'", secretary.getID());

                dataGridView1.DataSource = dv;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(constring);

            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO SecMes (Sender, Receiver, Body) VALUES (@Sender, @Receiver, @Body)", con);

            cmd.Parameters.Add("@Sender", student.getName());
            cmd.Parameters.Add("@Receiver", secretary.getID());
            cmd.Parameters.Add("@Body", textBox1.Text);

            if (cmd.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Inserting Data Successfully");
                con.Close();
                pictureBox1_Click(sender, e);   //  exit
            }
            else
            {
                MessageBox.Show("Inserting Data Failed");
            }
        }