hi there i have a database called employee and in that there is a table called EmpDetails and in that there is column namely firstname awhat i want to do is to return all the first names in the database.
i am using the 3 tier architecture.

from the dbcommection after executing a select query a datatable is being returned to the DAO class what from there how do i send the information to the Business layer


appricieate help
thanx

Here you do:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Feb153TyperArch
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BLL bll = new BLL();
            List<Customer> list = bll.GetCustomers_BLL();
            this.listBox1.DataSource = list;
            this.listBox1.DisplayMember = "name";
            this.listBox1.ValueMember = this.listBox1.DisplayMember;
        }
    }

    public class BLL
    {
        DAL dal;
        public BLL()
        {
            dal = new DAL();            
        }

        public List<Customer> GetCustomers_BLL()
        {
            return dal.GetCustomers_DAL();
        }
    }

    public class DAL
    {
        public List<Customer> GetCustomers_DAL()
        {
            List<Customer> list = new List<Customer>();          
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
            {
                string query = @"SELECT Name FROM Customers";
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Customer c = new Customer();
                        c.name = (string)reader[0];
                        list.Add(c);
                    }
                }
            }
            return list;
        }
    }

    public class Customer
    {
        public string name { get; set; }
    }
}

Hope it helps,
Mitja
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.