C#-SQL Server Silme-Güncelleme ve Listeleme Örneği

C#-SQL Server Silme-Güncelleme ve Listeleme Örneği için tıklayınız.

 

 

 

 

 

 

 

 

 

 

 

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;

namespace Guncelleme_Silme
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection(“Data Source=.\\SQLEXPRESS; Initial Catalog=ornek; Integrated Security=true;”);
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
string sorgu = “select * from kimlik where TCKimlikNo='”+textBox1.Text+”‘”;
//TCNO,Ad,Soyad,Doğumyer
SqlDataAdapter adp = new SqlDataAdapter(sorgu,conn);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
textBox2.Text = ds.Tables[0].Rows[0][0].ToString();
textBox3.Text = ds.Tables[0].Rows[0][1].ToString();
textBox4.Text = ds.Tables[0].Rows[0][2].ToString();
textBox5.Text = ds.Tables[0].Rows[0][3].ToString();
}
else
MessageBox.Show(“Böyle bir kayıt yok…”);
conn.Close();

}

private void button2_Click(object sender, EventArgs e)
{
//UPDATE TABLOADI SET ALAN =DEĞER WHERE KOŞUL
//conn.Open();
string sorgu = “update kimlik set ad='”+textBox3.Text+”‘, soyad='”+textBox4.Text+”‘,DogumYer='”+textBox5.Text+”‘ where TCKimlikNo='”+textBox2.Text+”‘”;
sorgucalistir(sorgu);
//SqlCommand cmd = new SqlCommand(sorgu,conn);
//cmd.ExecuteNonQuery();
//MessageBox.Show(“İşlem Başarılı…”);
//conn.Close();
}

private void button3_Click(object sender, EventArgs e)
{
//DELETE FROM TABLOADİ WHERE KOŞUL
//conn.Open();
string xyz = “delete from kimlik where TCKimlikNo='”+textBox2.Text+”‘ “;
sorgucalistir(xyz);
//SqlCommand cmd = new SqlCommand(sorgu,conn);
//cmd.ExecuteNonQuery();
//MessageBox.Show(“İşlem Başarılı…”);
//conn.Close();
}

private void button4_Click(object sender, EventArgs e)
{
conn.Open();
string sorgu = “select * from kimlik”;
//TCNO,Ad,Soyad,Doğumyer
SqlDataAdapter adp = new SqlDataAdapter(sorgu, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
void sorgucalistir(string sorgu)
{
conn.Open();
SqlCommand cmd = new SqlCommand(sorgu,conn);
cmd.ExecuteNonQuery();
MessageBox.Show(“İşlem başarılı…”);
conn.Close();
}
}
}

admin