0

Veri Güncelleme Örneği

 

 

 

C# ile Access veri tabanındaki veriyi güncelleme…
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 guncelle : Form
{
public guncelle()
{
InitializeComponent();
}
int deger;
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());
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
}

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 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 = “update bilgi set kisiAd='” + textBox1.Text + “‘,kisiSoyad='” + textBox2.Text + “‘,kisiTelNo='” + textBox3.Text + “‘,kisiAdres='” + textBox4.Text + “‘ where kisiId=”+deger+””;
OleDbCommand cmd = new OleDbCommand(sorgu, conn);
cmd.ExecuteNonQuery();
MessageBox.Show(“Veri Güncellendi..”);

conn.Close();
}
}
}

admin

Bir Cevap Yazın

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