Northwind Veritabanındaki Employees Tablosundan Firstname Ve Lastname'i Combobox'ta Gösterme

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.SqlClient;

namespace butunProjelerForm
{
    public partial class adoNetVeriAl : Form
    {
        public adoNetVeriAl()
        {
            InitializeComponent();
        }
        //using System.Data.SqlClient; 'ı Kütüphanelerin olduğu yere ekliyoruz

        string str = "Server= .; Database=Northwind; Integrated security=yes";
        private void adoNetVeriAl_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(str);
            SqlCommand cmd = new SqlCommand("select e.FirstName ,e.Lastname  from Employees e",con);

            if (con.State==ConnectionState.Closed)
            {
                con.Open();

            }
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cbAdSoyad.Items.Add(reader[0] +" "+reader[1]);
                }
            }
            reader.Close();
            con.Close();


        }
    }
}

Yorum Gönder

0 Yorumlar