C# ile Access Veri Tabanına Veri Ekleme için ….
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 ekleme : Form
{
public ekleme()
{
InitializeComponent();
}
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);
conn.Open();
string sorgu = “insert into bilgi (kisiAd,kisiSoyad,kisiTelNo,kisiAdres) values (@adi,@soyadi,@telno,@adres)”;
OleDbCommand cmd = new OleDbCommand(sorgu, conn);
cmd.Parameters.AddWithValue(“@adi”, textBox1.Text);
cmd.Parameters.AddWithValue(“@soyadi”, textBox2.Text);
cmd.Parameters.AddWithValue(“@telno”, textBox3.Text);
cmd.Parameters.AddWithValue(“@adres”, textBox4.Text);
cmd.ExecuteNonQuery();// cmd nesnesini çalıştır
MessageBox.Show(“Veri Eklendi..”);
conn.Close();
temizle();
}
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 = “select * from bilgi”; //sql cümlem
// Random rnd = new Random();
OleDbDataAdapter adp = new OleDbDataAdapter(sorgu, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
private void temizle()
{
foreach (Control nesne in this.Controls)
{
if (nesne is TextBox)
{
TextBox textbox = (TextBox)nesne;
textbox.Clear();
}
}
}
}
}