Using System. Collections. Generic
Download 291.91 Kb.
|
Raxmonov Azizbek 5
O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI MA`LUMOTLAR BAZASI FANIDAN 5-AMALIY ISH Bajardi: 315-21 guruh talabasi Raaxmonov Azizbek Tekshirdi: Qodirov Raximjon TOSHKENT 2022 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace Project_315_21 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string connectionString = "SERVER=localhost; PORT =3306; DATABASE = universitet; USERNAME = root; PASSWORD = 123456"; MySqlConnection connection; MySqlDataAdapter adapter; MySqlCommand command; DataSet dataset; int id = 0, k = 0; private void button1_Click(object sender, EventArgs e) { try { connection = new MySqlConnection(connectionString); connection.Open(); MessageBox.Show("Ulanish muvaffaqiyatli amalga oshirildi"); } catch(Exception ex) { MessageBox.Show(ex.Message); } } void select_function() { string sorov = "SELECT * FROM xodimlar"; dataset = new DataSet(); command = new MySqlCommand(sorov, connection); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); dataGridView1.DataSource = dataset.Tables[0]; } private void button2_Click(object sender, EventArgs e) { select_function(); } private void button3_Click(object sender, EventArgs e) { var natija = MessageBox.Show("Rostdan ham o'chirasmi?", "SAVOL", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (natija == DialogResult.Yes) { string sorov = "DELETE FROM xodimlar WHERE id = ("+id.ToString()+")"; command = new MySqlCommand(sorov, connection); adapter= new MySqlDataAdapter(command); command.ExecuteNonQuery(); select_function(); MessageBox.Show("O'chirildi"); } else { return; } } private void button4_Click(object sender, EventArgs e) { string sorov = "UPDATE xodimlar SET Ismi = @Ismi, Familyasi = @Familyasi, Yoshi = @Yoshi, Millati = @Millati, Tel = @Tel WHERE Id = @Id"; command = new MySqlCommand(sorov, connection); adapter = new MySqlDataAdapter(command); command.Parameters.AddWithValue("Ismi", dataGridView1.Rows[k].Cells[1].Value); command.Parameters.AddWithValue("Familyasi", dataGridView1.Rows[k].Cells[2].Value); command.Parameters.AddWithValue("Yoshi", Convert.ToInt32(dataGridView1.Rows[k].Cells[3].Value)); command.Parameters.AddWithValue("Millati", dataGridView1.Rows[k].Cells[4].Value); command.Parameters.AddWithValue("Tel", Convert.ToInt32(dataGridView1.Rows[k].Cells[5].Value)); command.Parameters.AddWithValue("Id", id); command.ExecuteNonQuery(); select_function(); MessageBox.Show("Yangilandi"); } private void textBox1_TextChanged(object sender, EventArgs e) { string sorov = "SELECT * FROM xodimlar WHERE ("+comboBox1.SelectedItem.ToString()+") LIKE ('%"+textBox1.Text+"%')"; dataset = new DataSet(); command = new MySqlCommand(sorov, connection); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); dataGridView1.DataSource = dataset.Tables[0]; } private void button6_Click(object sender, EventArgs e) { string name = textBox2.Text; string surname = textBox3.Text; int age = Convert.ToInt32(textBox4.Text); string nationality = textBox5.Text; int phone = Convert.ToInt32(textBox6.Text); string sorov = "INSERT INTO xodimlar(Ismi, Familyasi, Yoshi, Millati, Tel) VALUES ('" + name + "', '" + surname + "', '" + age + "','" + nationality + "','"+phone+"')"; command = new MySqlCommand(sorov, connection); adapter = new MySqlDataAdapter(command); command.ExecuteNonQuery(); select_function(); MessageBox.Show("Ma'lumot qo'shildi"); }
{ k = e.RowIndex; id = Convert.ToInt32(dataGridView1.Rows[k].Cells[0].Value); } } } Download 291.91 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling