0

C# ile Veritabanından Veri Silme

C# ile Veritabanından  seçilen verinin silinmesi…Ekran Alıntısı

 

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 veri_islemleri
{
public partial class silme : Form
{
public silme()
{
InitializeComponent();
}

int deger;
private void button1_Click(object sender, EventArgs e)
{
string connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Volkan\\documents\\visual studio 2012\\Projects\\veri_islemleri\\veri_islemleri\\ornek.accdb;Persist Security Info=True”;
OleDbConnection conn = new OleDbConnection(connString);
string sorgu = “select * from bilgi”;
conn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(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)
{
deger = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
}

private void button2_Click(object sender, EventArgs e)
{
string connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Volkan\\documents\\visual studio 2012\\Projects\\veri_islemleri\\veri_islemleri\\ornek.accdb;Persist Security Info=True”;
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
string sorgu = “delete from bilgi where kisiId=” + deger + “”;
OleDbCommand cmd = new OleDbCommand(sorgu, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(“Veri Silindi..”);
conn.Close();
}
}
}

admin

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir