Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
i want to convert this to DAL andBLL
 
    sqlDataReader myreader = null;
    SqlConnection sqlConn = null;
 
     cmbCat.Items.Clear();
    sqlConn = new SqlConnection("jjj");
    sqlConn.Open();
    SqlCommand sqlComm = new SqlCommand("SELECT from  where  ", sqlConn);
 
    myreader = sqlComm.ExecuteReader();
    if (myreader != null)
    {
        while (myreader.Read())
        {
 
            cmbCat.Items.Add(myreader["members"]);
 
        }
    }
 
     if (myreader != null)
    {
        
         myreader.Close();
        
        if (sqlConn != null)
        {
            if (sqlConn.State == ConnectionState.Open)
                sqlConn.Close();
        }
    }
Posted 24-Jan-13 14:22pm
Edited 24-Jan-13 14:24pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Create 2 classes 1 that hold all the connection information and executes the various database calls you need to make, GetTable, ExecutenonQuery, ExecuteScalar etc. This is your DAL.
 
The other class constructs the query according to the objects requirements and uses the DAL to get the data from the database. This is your BLL. I ALWAYS use stored procedures so I pass in a stored proc name and an array of parameters to my DAL. So my call looks like:
dtData = gDBO.GetTable(string.Format("{0}.{1}", cSchema, sProcName), arParam);
where schema is the procs schema, sProcName is the procedurename and arParam is an array of sql parameters.
 
There are many and varied designs for these classes
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
I think you need to understand first
3-Tier(Multi-Tier) Architecture And Why Do You Need It?
check this link 3-Tier(Multi-Tier) Architecture And Why Do You Need It?
 

How to create a 3-Tier Solution?
 
1. Open Visual Studio
2. Click File then New Project then expand Other Type Project then
select Visual Studio Solution. type the name of your solution
Example: MyFistSolution then Enter
 
The Visual Studion will create a solution
Solution 'MyFirstSolution' (0 projects)
 
Hover on solution then rigth click
then Add then New Solution Folder type DAL
 
Hover on solution then rigth click
then Add then New Solution Folder type BLL
 
Hover on solution the rigth click
tnen Add then New Solution Folder type UI
 
Now you have accomplished creating your three layer solution
 
How to create DAL project?
Hover on DAL folder right click ADD then New Project expand Visual C#
select Windows then Class Library type Data Access Layer
then OK
Now you have created you DAL tier.
 

How to create UI project?

 
Hover on UI rigth click then Add the New Project select Visual C#then Web the ASP.NET Web Application then type User Interface then then OK
 
Now you have created you UI Wb Site.
 
How to create BLL project?
Just follow instruction on DAL...
 
Hope this could help...
 
Do not forget to vote if could help. the highest vote is 5.
 
Regards,
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi
 
Create 2 Classes in 2 layers one is in DAL and another on is in BAL
 
The following steps help u to bind data to combobox
 
1)Create a class with function in DAL with return type as Datatable
 
Example:
 
Public Class DataAccess
{
        public Datatble GetDate()
        {
            Datatble dt = new Datatble();
 
            SqlConnection sqlConn = new SqlConnection("ABC");
 
            string CMD = "SELECT * FROM TABLE1";
            SqlDataAdapter da = new SqlDataAdapter(CMD, sqlConn);
            da.Fill(dt);
 
            return dt;
        }
}
 
2) Create a class
with funtion in BAL with return type as Datatable
Example:
 
Using DAL;
 
Public Class BusinessAceess
{
public Datatable FetchData()
{
 DataAccess objDataAccess=new  DataAccess();
 Datatble dt=objDataAccess.GetData();
} 
} 
 
3)Finally in Presentation Layer where the combobox exists
 
Private void BindCombobox()
      {
 
         BusinessAceess objBAL=new BusinessAceess();
 
          cmb.AutoCompleteSource = AutoCompleteSource.ListItems;
          cmb.DropDownStyle = ComboBoxStyle.DropDownList;
 
          cmb.DataSource = dt;
          cmb.DisplayMember ="Text";
          cmb.ValueMember = "Value"
       }
 
Hope this solution may help u Smile | :)
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100