Access Bağlantısı ile Listeleme

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

        private void button1_Click(object sender, EventArgs e)
        {
            string a, b, c;
            if (radioButton1.Checked)
            {
                textBox3.Text = "erkek";
            }
            if (radioButton2.Checked)
            {
                textBox3.Text = "kız";
            }
            OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\lab 102\\Desktop\\Yeni Microsoft Office Access Uygulaması.mdb");
            baglan.Open();
            OleDbCommand komut = new OleDbCommand("insert into bilgi(okulno,ad,cinsiyet) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')", baglan);
            komut.ExecuteNonQuery();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            if (radioButton3.Checked)
            {
                OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\lab 102\\Desktop\\Yeni Microsoft Office Access Uygulaması.mdb");
                baglan.Open();
                OleDbCommand komut = new OleDbCommand();
                komut.CommandText = "select * from bilgi where cinsiyet = 'erkek'";
                komut.Connection = baglan;
                OleDbDataReader oku = komut.ExecuteReader();
                while (oku.Read())
                {
                    listBox1.Items.Add(oku[0].ToString() + " " + oku[1].ToString() + " " + oku[2].ToString());
                }
                oku.Close();
                baglan.Close();
            }
            if (radioButton4.Checked)
            {
                OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\lab 102\\Desktop\\Yeni Microsoft Office Access Uygulaması.mdb");
                baglan.Open();
                OleDbCommand komut = new OleDbCommand();
                komut.CommandText = "select * from bilgi where cinsiyet = 'kız'";
                komut.Connection = baglan;
                OleDbDataReader oku = komut.ExecuteReader();
                while (oku.Read())
                {
                    listBox1.Items.Add(oku[0].ToString() + " " + oku[1].ToString() + " " + oku[2].ToString());
                }
                oku.Close();
                baglan.Close();
            }
        }
    }

Hiç yorum yok:

Yorum Gönder