using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { OleDbConnection baglan; OleDbCommand komut; OleDbDataAdapter da; void Listele()//Her prosedür içinden çağırabileceğimiz metot tanımladık. { baglan = new OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0;Data Source=deneme.accdb"); baglan.Open(); da = new OleDbDataAdapter("Select *From ogr", baglan); DataTable tablo = new DataTable(); da.Fill(tablo); dataGridView1.DataSource = tablo; baglan.Close(); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { dataGridView1.EnableHeadersVisualStyles = false; dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black; dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; dataGridView1.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("Times New Roman", 14, FontStyle.Bold); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; Listele(); } private void button1_Click(object sender, EventArgs e) { komut = new OleDbCommand("Insert into ogr (Kimlik,ad,soyad,adres) values (@Kimlik,@ad,@soyad,@adres)", baglan); komut.Parameters.AddWithValue("@Kimlik", Convert.ToInt32(textBox1.Text)); komut.Parameters.AddWithValue("@ad", textBox2.Text); komut.Parameters.AddWithValue("@soyad", textBox3.Text); komut.Parameters.AddWithValue("@adres", textBox4.Text); baglan.Open(); komut.ExecuteNonQuery(); baglan.Close(); Listele(); } private void button2_Click(object sender, EventArgs e) { { komut = new OleDbCommand("Delete From ogr Where Kimlik=@Kimlik", baglan); komut.Parameters.AddWithValue("@Kimlik", dataGridView1.CurrentRow.Cells[0].Value); baglan.Open(); komut.ExecuteNonQuery(); baglan.Close(); Listele(); } } private void button3_Click(object sender, EventArgs e) { { komut = new OleDbCommand("Update ogr Set ad=@ad,soyad=@soyad,adres=@adres Where Kimlik=@Kimlik", baglan); komut.Parameters.AddWithValue("@ad", textBox2.Text); komut.Parameters.AddWithValue("@soyad", textBox3.Text); komut.Parameters.AddWithValue("@adres", textBox4.Text); komut.Parameters.AddWithValue("@Kimlik", Convert.ToInt32(textBox1.Text)); baglan.Open(); komut.ExecuteNonQuery(); baglan.Close(); Listele(); } } private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString(); textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString(); textBox3.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString(); textBox4.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString(); } private void button4_Click(object sender, EventArgs e) { dataGridView1.Columns["Kimlik"].ToolTipText = "Alan adı Kimlik olarak girilmiştir"; dataGridView1.Columns["ad"].ToolTipText = "Alan adı Ad olarak girilmiştir"; dataGridView1.Columns["soyad"].ToolTipText = "Alan Soyad olarak girilmiştir"; dataGridView1.Columns["adres"].ToolTipText = "Alan adı Adres olarak girilmiştir"; } private void button5_Click(object sender, EventArgs e) { dataGridView1.Columns["ad"].Visible = false; dataGridView1.Columns["soyad"].Visible = false; dataGridView1.Columns["adres"].Visible = false; } } }