C# Access Bağlantısı ve Kaydet - Listele - Güncelle - KayıtSil
EMRE KOŞAR
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 WindowsFormsApplication34
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection elma = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=EMRE.mdb");
private void button4_Click(object sender, EventArgs e)
{
//listele
listBox1.Items.Clear();
int m = 0;
OleDbDataAdapter remzi = new OleDbDataAdapter("select * from emre", elma);
DataSet betul = new DataSet();
remzi.Fill(betul, "ELMA");
int a = betul.Tables[0].Rows.Count;
for (int i = 0; i < a; i++)
{
listBox1.Items.Add(++m + ")" + betul.Tables[0].Rows[i][0].ToString() + " " + betul.Tables[0].Rows[i][1].ToString() + " " + betul.Tables[0].Rows[i][2].ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
// kadetme
elma.Open();
OleDbCommand armut = new OleDbCommand("insert into emre(okulno,ad,soyad) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')", elma);
armut.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
elma.Close();
}
private void button2_Click(object sender, EventArgs e)
{
//güncelleme
elma.Open();
OleDbCommand armut = new OleDbCommand("update emre set ad='" + textBox2.Text + "' where okulno ='" + textBox1.Text + "'", elma);
OleDbCommand q = new OleDbCommand("update emre set soyad='" + textBox3.Text + "' where okulno ='" + textBox1.Text + "'", elma);
armut.ExecuteNonQuery();
q.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
elma.Close();
}
private void button3_Click(object sender, EventArgs e)
{
// kayıt silme
elma.Open();
OleDbCommand w = new OleDbCommand("delete*from emre where okulno = '"+textBox1.Text +"'", elma);
w.ExecuteNonQuery();
elma.Close();
}
}
}
Kaydol:
Kayıtlar (Atom)
Hiç yorum yok:
Yorum Gönder