Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to convert this to DAL andBLL

C#
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
Updated 18-May-17 9:14am
v2

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:
C#
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
 
Share this answer
 
Comments
Member 11452768 16-Feb-15 20:17pm    
Jani
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,
 
Share this answer
 
Comments
Member 11452768 16-Feb-15 20:18pm    
l[
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:

C#
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:

C#
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

C#
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 :-)
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900