Veritabanından combobox’a veri çekme örneği için tıklayınız.
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 combo : Form
{
public combo()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
oleDbConnection1.Open();
string sorgu = “select kisiAd from bilgi”;
OleDbDataAdapter adp = new OleDbDataAdapter(sorgu,oleDbConnection1);
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());
oleDbConnection1.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
oleDbConnection1.Open();
string sorgu = “select kisiSoyad from bilgi where kisiAd='”+comboBox1.Text+”‘”;
OleDbDataAdapter adp = new OleDbDataAdapter(sorgu, oleDbConnection1);
DataSet ds = new DataSet();
adp.Fill(ds);
label1.Text = ds.Tables[0].Rows[0][0].ToString();
oleDbConnection1.Close();
}
}
}