Access Bağlantısı ve Radiobutton'a Göre 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 WindowsFormsApplication52
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
textBox3.Text= "erkek";
}
if (radioButton2.Checked)
{
textBox3.Text = "kız";
}
OleDbConnection elma = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=okul.mdb");
elma.Open();
OleDbCommand armut = new OleDbCommand("insert into sinif(okulno,ad,cinsiyet) values('" + textBox1.Text + "','" + textBox2.Text + "','"+textBox3.Text+"')", elma);
armut.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
int m=0;
OleDbConnection elma = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=okul.mdb");
elma.Open();
OleDbDataAdapter remzi = new OleDbDataAdapter("select * from sinif", elma);
DataSet betul = new DataSet();
remzi.Fill(betul, "gonca");
int a = betul.Tables[0].Rows.Count;
if (radioButton5.Checked)
{
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());
}
}
if (radioButton3.Checked)
{
for (int i = 0; i < a; i++)
{
if (betul.Tables[0].Rows[i][2].ToString() == "kız")
{
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());
}
}
}
if (radioButton4.Checked)
{
for (int i = 0; i < a; i++)
{
if (betul.Tables[0].Rows[i][2].ToString() == "erkek")
{
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());
}
}
}
}
}
}
Kaydol:
Kayıtlar (Atom)
Hiç yorum yok:
Yorum Gönder