Untitled
public partial class Form4 : Form { public Form4() { InitializeComponent(); } OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\adnanideal\\BistIslemler\\TradeListesi.accdb"); OleDbCommand command; OleDbDataAdapter da; private void TradeListele() { int t = Environment.TickCount; // Veritabanı bağlantısını aç conn.Open(); // Tüm verileri çağır ve DataGridView'e yükle da = new OleDbDataAdapter("SELECT * FROM biriktir ORDER BY Kimlik DESC ", conn); DataSet table = new DataSet(); da.Fill(table); dataGridView2.DataSource = table.Tables[0]; dataGridView2.VirtualMode = true; // DataGridView'in ilk sütununu azalan sırayla sırala // dataGridView2.Sort(dataGridView2.Columns[0], ListSortDirection.Descending); // SQL sorgusu ile 3 hesabın kayıt sayısını ve biriken_lot toplamını al string query = "SELECT hesap, COUNT(*) AS record_count, SUM(biriken_lot) AS total_lot " + "FROM biriktir " + "WHERE hesap IN ('6652', '53607', '223351') " + "GROUP BY hesap"; da = new OleDbDataAdapter(query, conn); DataTable summaryTable = new DataTable(); da.Fill(summaryTable); // Veritabanı bağlantısını kapat conn.Close(); // Kayıtları döngü ile kontrol et ve ilgili label'lara yaz foreach (DataRow row in summaryTable.Rows) { string hesapNo = row["hesap"].ToString(); int recordCount = Convert.ToInt32(row["record_count"]); decimal totalLot = row["total_lot"] != DBNull.Value ? Convert.ToDecimal(row["total_lot"]) : 0; // Hesap numarasına göre ilgili label'a verileri yazdır if (hesapNo == "6652") { label2.Text = recordCount.ToString(); // Kayıt sayısı label12.Text = totalLot.ToString("N0") + " Lot"; // Biriken lot toplamı } else if (hesapNo == "53607") { label3.Text = recordCount.ToString(); label13.Text = totalLot.ToString("N0") + " Lot"; } else if (hesapNo == "223351") { label4.Text = recordCount.ToString(); label14.Text = totalLot.ToString("N0") + " Lot"; } } // dataGridView2.Columns[0].Width = 50; // 2. sütunun genişliğini 150 piksel yapar // // dataGridView2.Columns[1].Width = 100; // 2. sütunun genişliğini 150 piksel yapar // dataGridView2.Columns[2].Width = 150; // 2. sütunun genişliğini 150 piksel yapar int t2 = Environment.TickCount - t; label19.Text = t2.ToString(); }
Leave a Comment