C# Kodları:
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 System.Data.SqlClient;//Sql Bağlantısını Oluşturduk
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
SqlConnection Baglanti = new SqlConnection("Data Source=ACER\\SQLEXPRESS;Initial Catalog=KisiBilgileri;Integrated Security=True");
public void Temizle()
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
public void Goster(string Veriler)
{
SqlDataAdapter Da = new SqlDataAdapter(Veriler, Baglanti);
DataSet Ds = new DataSet();
Da.Fill(Ds);
dataGridView1.DataSource = Ds.Tables[0];
Temizle();
}
private void Kaydet()
{
Baglanti.Open();
SqlCommand Komut = new SqlCommand("insert into Kisiler (AdSoyad,Yas,Ilce,Meslek) values (@Adi,@Yasi,@Ilcesi,@Meslegi)", Baglanti);
Komut.Parameters.AddWithValue("@Adi", textBox1.Text);
Komut.Parameters.AddWithValue("@Yasi", textBox2.Text);
Komut.Parameters.AddWithValue("@Ilcesi", textBox3.Text);
Komut.Parameters.AddWithValue("@Meslegi", textBox4.Text);
Komut.ExecuteNonQuery();
Goster("select * from Kisiler");
Baglanti.Close();
}
public void Sil()
{
Baglanti.Open();
SqlCommand Komut = new SqlCommand("delete from Kisiler where AdSoyad=@Adi",Baglanti);
Komut.Parameters.AddWithValue("@Adi", textBox5.Text);
Komut.ExecuteNonQuery();
Goster("select * from Kisiler");
Baglanti.Close();
}
public void Ara()
{
Baglanti.Open();
SqlCommand Komut = new SqlCommand("select * from Kisiler where AdSoyad like '%"+ textBox6.Text +"%'",Baglanti);
SqlDataAdapter Da = new SqlDataAdapter(Komut);
DataSet Ds = new DataSet();
Da.Fill(Ds);
dataGridView1.DataSource = Ds.Tables[0];
Baglanti.Close();
Temizle();
}
public void Guncelle()
{
Baglanti.Open();
SqlCommand Komut = new SqlCommand("update Kisiler set Yas='"+textBox2.Text+"',Ilce='"+ textBox3.Text + "',Meslek='"+ textBox4.Text + "' where AdSoyad='"+textBox1.Text+"'",Baglanti);
Komut.ExecuteNonQuery();
Goster("select * from Kisiler");
Baglanti.Close();
Temizle();
}
private void button1_Click(object sender, EventArgs e)
{
Goster("select * from Kisiler");
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1 == null && textBox2== null && textBox3 == null && textBox4 == null)
{
MessageBox.Show("Değer Girin");
}
Kaydet();
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
//**************
}
private void button3_Click(object sender, EventArgs e)
{
Sil();
}
private void button4_Click(object sender, EventArgs e)
{
Ara();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int SeciliAlan = dataGridView1.SelectedCells[0].RowIndex;
textBox1.Text = dataGridView1.Rows[SeciliAlan].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[SeciliAlan].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[SeciliAlan].Cells[2].Value.ToString();
textBox4.Text = dataGridView1.Rows[SeciliAlan].Cells[3].Value.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
Guncelle();
}
}
}
Hiç yorum yok :
Yorum Gönder