0

İl-İlçe C# Örneği

İl-İlçe C# Örneği için tıklayınız.

ililce

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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection conn = new OleDbConnection
(“Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\\Users\\PC\\Documents\\visual studio 2013\\Projects\\WindowsFormsApplication3\\WindowsFormsApplication3\\iller.accdb ;Persist Security Info=True”);
private void Form1_Load(object sender, EventArgs e)
{
conn.Open();
string sorgu = “select sehir from iller”;
OleDbDataAdapter adp = new OleDbDataAdapter(sorgu,conn);
DataSet ds = new DataSet();
adp.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count – 1; i++)
comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
conn.Close();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
conn.Open();
string sorgu = “select ilce from ilceler where sehir=(select id from iller where sehir='”+comboBox1.Text+”‘)”;
OleDbDataAdapter adp = new OleDbDataAdapter(sorgu, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
for (int i = 0; i <= ds.Tables[0].Rows.Count – 1; i++)
comboBox2.Items.Add(ds.Tables[0].Rows[i][0].ToString());
conn.Close();
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
label3.Text =comboBox1.Text +” “+ comboBox2.Text;
}

 

}
}

admin

Bir cevap yazın

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