Arama butonu
Bu konudaki kullanıcılar: 1 misafir
0
Cevap
171
Tıklama
0
Öne Çıkarma
C# ComboBox alt kategori oluşturma nasıl yapılır (Access) Hatta alıyorum
M
4 yıl
Er
Konu Sahibi

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

OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data source=otogalerim.mdb");
void temizle()
{
textBox2.Text = "";
comboBox4.Text = "";
comboBox6.Text = "";
textBox4.Text = "";
comboBox1.Text = "";
comboBox5.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
textBox1.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
baglan.Open();
var komut = new OleDbCommand(@"insert into oto
(Plaka,marka,model,aractipi,renk,yil,
aracdurumu,satısdurumu,fiyat) values
(@Plaka,@marka,@model,@aractipi,@renk,@yil,
@aracdurumu,@satısdurumu,@fiyat)", baglan);

komut.Parameters.Add("@Plaka", OleDbType.VarChar).Value = textBox2.Text;
komut.Parameters.Add("@marka", OleDbType.VarChar).Value = comboBox4.Text;
komut.Parameters.Add("@model", OleDbType.VarChar).Value = comboBox6.Text;
komut.Parameters.Add("@aractipi", OleDbType.VarChar).Value = textBox4.Text;
komut.Parameters.Add("@renk", OleDbType.VarChar).Value = comboBox1.Text;
komut.Parameters.Add("@yil", OleDbType.VarChar).Value = comboBox5.Text;
komut.Parameters.Add("@aracdurumu", OleDbType.VarChar).Value = comboBox2.Text;
komut.Parameters.Add("@satısdurumu", OleDbType.VarChar).Value = comboBox3.Text;
decimal.TryParse(textBox1.Text, out decimal fiyat);
komut.Parameters.Add("@fiyat", OleDbType.Decimal).Value = fiyat;

komut.ExecuteNonQuery();
MessageBox.Show("Kayıt yapıldı...");

baglan.Close();
}

private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox4.SelectedValue != null)
{
comboBox6.DataSource = null;
comboBox6.Items.Clear();

DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(@"select * from aracsecim_2 where marka = @model", bagCumle);
da.SelectCommand.Parameters.Add("@model", OleDbType.VarChar).Value = comboBox4.SelectedValue;
da.Fill(dt);
comboBox6.DataSource = dt;
comboBox6.DisplayMember = "model";
comboBox6.ValueMember = "id";

}
}
string bagCumle = @"Provider=Microsoft.Jet.Oledb.4.0;Data source=otogalerim.mdb";
private void aracislemadmin_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
new OleDbDataAdapter("select * from aracsecim_1 ORDER BY id ASC ", bagCumle).Fill(dt);
comboBox4.DataSource = dt;
comboBox4.ValueMember = "id";
comboBox4.DisplayMember = "marka";
}

private void menüyeDönToolStripMenuItem_Click(object sender, EventArgs e)
{
adminmonu menu = new adminmonu();
menu.Show();
this.Hide();
}
}
}


Hatta aldığım kod satırı bu

private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox4.SelectedValue != null)
{
comboBox6.DataSource = null;
comboBox6.Items.Clear();

DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(@"select * from aracsecim_2 where marka = @model", bagCumle);
da.SelectCommand.Parameters.Add("@model", OleDbType.VarChar).Value = comboBox4.SelectedValue;
da.Fill(dt);
comboBox6.DataSource = dt;
comboBox6.DisplayMember = "model";
comboBox6.ValueMember = "id";

}
}








< Resime gitmek için tıklayın >



DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.