public updateStudents() { InitializeComponent(); MySQLi sql = new MySQLi(); SQLiteDataReader reader = sql.query("SELECT * FROM `students`"); int i = 0; foreach (DbDataRecord record in reader) { students[0, i] = record["fio"].ToString(); comboBox1.Items.Add(record["fio"].ToString()); students[1, i] = record["b_day"].ToString(); students[2, i] = record["mobile"].ToString(); students[3, i] = record["address"].ToString(); students[4, i] = record["fio_parent"].ToString(); students[5, i] = record["fio_mobile"].ToString(); i++; } /*try * { * today = monthCalendar1.TodayDate; * } * catch(NullReferenceException) * { * * } * /*monthCalendar1.MinDate = new DateTime(today.Year - 60, today.Month, today.Day); * monthCalendar1.MaxDate = today;*/ }
private void button1_Click(object sender, EventArgs e) { if ((textBox1.Text == "") || (textBox4.Text == "") || (textBox5.Text == "") || (textBox1.Text == " ") || (textBox4.Text == " ") || (textBox5.Text == " ") || (maskedTextBox1.Text == "") || (maskedTextBox2.Text == "") || (maskedTextBox3.Text == "")) { MessageBox.Show("Введите все данные с форм"); } else { string[] data = new string[10]; data[0] = textBox1.Text; data[1] = maskedTextBox1.Text; data[2] = maskedTextBox2.Text; data[3] = textBox4.Text; data[4] = textBox5.Text; data[5] = maskedTextBox3.Text; MySQLi sql = new MySQLi(); string query = "INSERT INTO `students` VALUES(null, \"" + data[0] + "\", \"" + data[1] + "\", \"" + data[2] + "\", \"" + data[3] + "\", \"" + data[4] + "\", \"" + data[5] + "\");"; sql.query(query); MessageBox.Show("Запись добавлена"); this.DialogResult = DialogResult.OK; this.Close(); } }
private void addRowsFromDB() { MySQLi sql = new MySQLi(); SQLiteDataReader reader = sql.query("SELECT * FROM `students`"); string[] data = new string[10]; foreach (DbDataRecord record in reader) { data[0] = record["fio"].ToString(); data[1] = record["b_day"].ToString(); data[2] = record["mobile"].ToString(); data[3] = record["address"].ToString(); data[4] = record["fio_parent"].ToString(); data[5] = record["fio_mobile"].ToString(); dataGridView1.Rows.Add(data); } }