Adding, deleting, updating, searching, and showing commands in DataGridView are used in our program (in Microsoft Visual Studio environment, “using System.Data.OLEDB;” we must add the library to our programs)
C# Database Options
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | string a = "Provider=Microsoft.ACE.OleDb.12.0;Data source=personel.accdb"; string askerlik; private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked == true) { askerlik = "Yaptı"; } else { askerlik = "Yapmadı"; } OleDbConnection baglan = new OleDbConnection(a); baglan.Open(); string save = "insert into kimlik([TC],[Ad],[Soyad],[Cinsiyet],[Askerlik]) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + comboBox1.Text + "','" + askerlik+"')"; OleDbCommand kaydet = new OleDbCommand(save, baglan); kaydet.ExecuteNonQuery(); baglan.Close(); } |
C# Database Update
1 2 3 4 5 6 7 8 9 | private void button2_Click(object sender, EventArgs e) { OleDbConnection baglan = new OleDbConnection(a); baglan.Open(); string guncelle = "update kimlik set Ad='" + textBox2.Text + "',Soyad='" + textBox3.Text + "' where TC='" + textBox1.Text + "' "; OleDbCommand update = new OleDbCommand(guncelle, baglan); update.ExecuteNonQuery(); baglan.Close(); } |
C# Database Delete
1 2 3 4 5 6 7 8 9 | private void button3_Click(object sender, EventArgs e) { OleDbConnection baglan = new OleDbConnection(a); baglan.Open(); string sil = "delete from kimlik where TC='" + textBox1.Text + "'"; OleDbCommand delete = new OleDbCommand(sil, baglan); delete.ExecuteNonQuery(); baglan.Close(); } |
C# Database Show with Datagridview
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | private void Form1_Load(object sender, EventArgs e) { radioButton2.Enabled = false; radioButton1.Enabled = false; string sorgu = "select * from kimlik"; OleDbConnection baglan = new OleDbConnection(a); baglan.Open(); OleDbDataAdapter getir = new OleDbDataAdapter(sorgu, baglan); DataSet göster = new DataSet(); getir.Fill(göster,"kimlik"); dataGridView1.DataSource=göster.Tables["kimlik"]; getir.Dispose(); baglan.Close(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.Text == "Erkek") { radioButton1.Enabled = true; radioButton2.Enabled = true; } if (comboBox1.Text == "Bayan") { radioButton1.Enabled = false; radioButton2.Enabled = false; } } |
C# Database Bringing Information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | private void button4_Click(object sender, EventArgs e) { OleDbConnection baglan = new OleDbConnection(a); baglan.Open(); OleDbCommand sorgu = new OleDbCommand("select * from kimlik order by TC", baglan); OleDbDataReader datare; datare = sorgu.ExecuteReader(); while (datare.Read()) { string b = Convert.ToString(textBox1.Text); if (b == datare[0].ToString()) { textBox2.Text = datare[1].ToString(); textBox3.Text = datare[2].ToString(); comboBox1.Text =datare[3].ToString(); } } datare.Close(); baglan.Close(); } |
Thanks for visit us, if you have any issue please comment.
I'm constantly amazed by the vast collection of films and series available on Soap2Day.