C# Hastane Kayıt Programı (Kaydetme,Listeleme, Arama, Güncelleme ve Silme)-Nesne Tabanlı Programlama
C# Hastane Kayıt Programı Örneği
Kaydetme,Listeleme, Arama, Güncelleme ve Silme işlemlerinin hepsini kapsamaktadır.
Veritabanı Bilgileri:
Veritabanı Adı : hastacorbasitasta
Tablo Adı : hesta_tbl
Alan Adları:—————— Veri Türleri
hastatc —————— Metin
hastaadi —————— Metin
hastasoyadi —————— Metin
yattigibolum —————– Metin
dradsoyad —————— Metin
odano —————— Sayı
yattigitar —————— Tarih
ucret —————— Para Birimi
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace basketbolhuzur
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//veri tabanı bağlantısını yapıyoruz.
OleDbConnection baglan =
new OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hastacorbasitasta.accdb”);
//Kaydetme
private void button2_Click(object sender, EventArgs e)
{
string hastatc = textBox1.Text;
string hastaadi = textBox2.Text;
string hastasoyadi = textBox3.Text;
string yattigibolum = textBox4.Text;
string dradsoyad = textBox5.Text;
string odano = textBox6.Text;
string yattigitar = dateTimePicker1.Text;
double ucret = Convert.ToDouble(textBox8.Text);
baglan.Open();
OleDbCommand komut = new OleDbCommand(“insert into hesta_tbl(hastatc,hastaadi,hastasoyadi,yattigibolum,dradsoyad,odano,yattigitar,ucret) values(‘” + hastatc + “‘,'” + hastaadi + “‘,'” + hastasoyadi + “‘,'” + yattigibolum + “‘,'” + dradsoyad + “‘,'” + odano + “‘,'” + yattigitar + “‘,”+ ucret + “)”, baglan);
komut.ExecuteNonQuery();
baglan.Close();
MessageBox.Show(“İşleminiz başarıyla gerçekleştirilmiştir.”);
}
//Listeleme
private void button3_Click(object sender, EventArgs e)
{
baglan.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(“select * from hesta_tbl”, baglan);
DataSet ds = new DataSet();
adapter.Fill(ds, “hesta_tbl”);
dataGridView1.DataSource = ds.Tables[“hesta_tbl”];
baglan.Close();
}
//BUL
private void button1_Click(object sender, EventArgs e)
{
string hastatc = textBox7.Text;
baglan.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(“select * from hesta_tbl where hastatc='” + textBox7.Text + “‘”, baglan);
DataSet ds = new DataSet();
adapter.Fill(ds, “hesta_tbl”);
dataGridView1.DataSource = ds.Tables[“hesta_tbl”];
baglan.Close();
}
//Getir
private void button4_Click(object sender, EventArgs e)
{
string hastatc = textBox9.Text;
int var = 0;
baglan.Open();
OleDbCommand komut = new OleDbCommand(“select * from hesta_tbl where hastatc='” + textBox9.Text + “‘”, baglan);
komut.ExecuteNonQuery();
OleDbDataReader reader = komut.ExecuteReader();
while (reader.Read())
{
textBox10.Text = reader[“ucret”].ToString();
textBox11.Text = reader[“odano”].ToString();
textBox12.Text = reader[“dradsoyad”].ToString();
textBox13.Text = reader[“yattigibolum”].ToString();
textBox14.Text = reader[“hastasoyadi”].ToString();
textBox15.Text = reader[“hastaadi”].ToString();
textBox16.Text = reader[“hastatc”].ToString();
textBox18.Text = reader[“yattigitar”].ToString();
var = 1;
}
if (var == 0)
{
MessageBox.Show(“kayıt bulunamadı”);
}
reader.Close();
baglan.Close();
}
//GÜNCELLEME
private void button6_Click(object sender, EventArgs e)
{
string ucret = textBox10.Text;
string odano = textBox11.Text;
string dradsoyad = textBox12.Text;
string yattigibolum = textBox13.Text;
string hastasoyadi = textBox14.Text;
string hastaadi = textBox15.Text;
string hastatc = textBox16.Text;
string yattigitar = textBox18.Text;
baglan.Open();
OleDbCommand komut = new OleDbCommand(“update hesta_tbl set ucret='” + ucret + “‘, odano='” + odano + “‘, dradsoyad='” + dradsoyad + “‘, yattigibolum='” + yattigibolum + “‘,hastasoyadi='” + hastasoyadi + “‘, hastaadi='” + hastaadi + “‘,hastatc='” + hastatc + “‘, yattigitar='” + yattigitar + “‘ where hastatc='” + hastatc + “‘”, baglan);
komut.ExecuteNonQuery();
baglan.Close();
MessageBox.Show(“Düzenleme işleminiz başarıyla gerçekleşti.”);
baglan.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(“select * from hesta_tbl”, baglan);
DataSet ds = new DataSet();
adapter.Fill(ds, “hesta_tbl”);
dataGridView1.DataSource = ds.Tables[“hesta_tbl”];
baglan.Close();
MessageBox.Show(“Düzenleme işleminiz başarıyla gerçekleşti.”);
}
//SİLME
private void button5_Click(object sender, EventArgs e)
{
string ucret = textBox10.Text;
string odano = textBox11.Text;
string dradsoyad = textBox12.Text;
string yattigibolum = textBox13.Text;
string hastasoyadi = textBox14.Text;
string hastaadi = textBox15.Text;
string hastatc = textBox16.Text;
string yattigitar = textBox16.Text;
baglan.Open();
OleDbCommand komut = new OleDbCommand(“delete * from hesta_tbl where hastatc='” + textBox9.Text + “‘”, baglan);
komut.ExecuteNonQuery();
OleDbDataAdapter adapter = new OleDbDataAdapter(“select * from hesta_tbl”, baglan);
DataSet ds = new DataSet();
adapter.Fill(ds, “hesta_tbl”);
dataGridView1.DataSource = ds.Tables[“hesta_tbl”];
baglan.Close();
MessageBox.Show(“kaydınız silinmiştir”);
}
}
}