C
ListBoxtaki Verileri Veritabanına Ekleme
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace listboxVeriGonder { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if(textBox1.Text!="") { listBox1.Items.Add(textBox1.Text); textBox1.Text = ""; } } OleDbConnection con; OleDbCommand cmd; private void button2_Click(object sender, EventArgs e) { if(listBox1.Items.Count!=0) { string sql = "INSERT INTO Kategori (ad) VALUES(@ad)"; con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=vt.accdb"); foreach (string kategori in listBox1.Items) { cmd = new OleDbCommand(sql, con); cmd.Parameters.AddWithValue("@ad", kategori); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } MessageBox.Show("Kayıt Eklendi"); } else { MessageBox.Show("Listbox' ta Veri Yok"); } } } }