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.OleDb;
namespace tc_kontrol.
{
public partial class Form1 : Form.
{
OleDbConnection baglanti;
OleDbCommand komut;
OleDbDataAdapter da;
public Form1()
{
InitializeComponent();
}
void KisiListele()
{
baglanti = new OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0;Data Source=vtogrenci.accdb");
baglanti.Open();
da = new OleDbDataAdapter("Select *From ogrenci", baglanti);
DataTable tablo = new DataTable();
da.Fill(tablo);
dataGridView1.DataSource = tablo;
baglanti.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
KisiListele();
}
public int VarMi(string aranan)
{
int sonuc;
baglanti = new OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0;Data Source=vtogrenci.accdb");
string sorgu = "Select COUNT(tc) from ogrenci WHERE tc='"+aranan+"'";
komut = new OleDbCommand(sorgu, baglanti);
baglanti.Open();
sonuc=Convert.ToInt32(komut.ExecuteScalar());
baglanti.Close();
return sonuc;
}
private void button1_Click(object sender, EventArgs e)
{
if (VarMi(txtTc.Text) != 0)
{
MessageBox.Show("Bu TC Numara ile daha önce kayıt yapılmış");
}
else.
{
string sorgu = "Insert into ogrenci (tc,ad,soyad) values (@tc,@ad,@soyad)";
komut = new OleDbCommand(sorgu, baglanti);
komut.Parameters.AddWithValue("@tc", Convert.ToInt32(txtTc.Text));
komut.Parameters.AddWithValue("@ad", txtAd.Text);
komut.Parameters.AddWithValue("@soyad", txtSoyad.Text);
baglanti.Open();
komut.ExecuteNonQuery();
baglanti.Close();
KisiListele();
}
}
}
}