Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            string        str  = @"Data Source=KOTO;Initial catalog=K;integrated Security=True  ";
            SqlConnection conn = new SqlConnection(str);

            conn.Open();
            string     selectsql = "TRUNCATE TABLE Message";
            SqlCommand cmd       = new SqlCommand(selectsql, conn);

            cmd.CommandType = CommandType.Text;
            SqlDataReader sdr;

            sdr = cmd.ExecuteReader();
            conn.Close();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                string        str2  = @"Data Source=KOTO;Initial catalog=K;integrated Security=True  ";
                SqlConnection conn2 = new SqlConnection(str2);
                conn2.Open();
                string     StudentName     = dataGridView1.Rows[i].Cells[0].Value.ToString();
                string     Tel             = dataGridView1.Rows[i].Cells[1].Value.ToString();
                string     StudentSex      = dataGridView1.Rows[i].Cells[2].Value.ToString();
                string     StudentBirthday = dataGridView1.Rows[i].Cells[3].Value.ToString();
                string     StudentQQ       = dataGridView1.Rows[i].Cells[4].Value.ToString();
                string     Homeaddress     = dataGridView1.Rows[i].Cells[5].Value.ToString();
                string     Email           = dataGridView1.Rows[i].Cells[6].Value.ToString();
                string     Job             = dataGridView1.Rows[i].Cells[7].Value.ToString();
                string     selectsql2      = "insert into Message values('" + StudentName + "','" + Tel + "','" + StudentSex + "','" + StudentBirthday + "','" + StudentQQ + "','" + Homeaddress + "','" + Email + "','" + Job + "')";
                SqlCommand cmd2            = new SqlCommand(selectsql2, conn2);
                cmd2.CommandType = CommandType.Text;
                SqlDataReader sdr2;
                sdr2 = cmd2.ExecuteReader();
                conn2.Close();
            }
            check a = new check();

            a.Show();
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (name.Text == "" || Tel.Text == "" || sex.Text == "" || QQ.Text == "" || address.Text == "" || Email.Text == "" || job.Text == "")
            {
                M.Text = "有未输入的项目";
            }
            else
            {
                if (radioButton1.Checked)
                {
                    sex.Text = "男";
                }
                else if (radioButton2.Checked)
                {
                    sex.Text = "女";
                }
                string        str  = @"Data Source=KOTO;Initial catalog=K;integrated Security=True  ";
                SqlConnection conn = new SqlConnection(str);
                conn.Open();
                string     selectsql = "insert into Message values('" + name.Text + "','" + Tel.Text + "','" + sex.Text + "','" + dateTimePicker1.Value.Date.ToString("yyyy.mm.dd") + "','" + QQ.Text + "','" + address.Text + "','" + Email.Text + "','" + job.Text + "')";
                SqlCommand cmd       = new SqlCommand(selectsql, conn);
                cmd.CommandType = CommandType.Text;
                SqlDataReader sdr;
                sdr = cmd.ExecuteReader();
                conn.Close();
                name.Text    = "";
                QQ.Text      = "";
                address.Text = "";
                Tel.Text     = "";
                job.Text     = "";
                Email.Text   = "";


                check a = new check();
                a.Show();
            }
        }