如何使用DAL,BLL从数据库中读取组合框 [英] how to make combobox read from database using DAL ,BLL

查看:107
本文介绍了如何使用DAL,BLL从数据库中读取组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将此转换为DAL和BLL



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();
    }
}

推荐答案

创建包含所有连接信息并执行的2个类1你需要做的各种数据库调用,GetTable,ExecutenonQuery,ExecuteScalar等。这是你的DAL。



另一个类根据对象要求和用途构造查询DAL从数据库中获取数据。这是你的BLL。我总是使用存储过程,所以我将存储过程名称和参数数组传递给我的DAL。所以我的调用如下:

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);



其中schema是procs模式,sProcName是procedurename,arParam是sql参数数组。



有许多不同的设计这些课程


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






我想你需要先理解

3-Tier(多层体系结构以及为什么需要它?

检查此链接 3层(多层)架构以及你为什么需要它?





如何创建3层解决方案?



1.打开Visual Studio

2.点击文件然后新项目然后展开其他类型项目然后

选择< b> Visual Studio解决方案。输入你的解决方案的名称

示例:MyFistSolution然后输入



Visual Studion将创建一个解决方案

解决方案'MyFirstSolution'(0个项目)



将鼠标悬停在解决方案上然后点击

然后添加然后新解决方案文件夹键入 DAL



将鼠标悬停在解决方案上然后点击

然后添加然后新解决方案文件夹键入 BLL



Hover解决方案点击

tnen 添加然后新解决方案文件夹键入 UI



现在你已经完成了创建三层解决方案



如何创建DAL项目?

将鼠标悬停在 DAL 文件夹上,右键单击 ADD ,然后新建项目展开 Visual C#

选择 Windows 然后类库键入数据访问层

然后确定

现在你有了cr给你DAL等级。





如何创建UI项目?




将鼠标悬停在用户界面上,然后点击添加 新建项目选择 Visual C#然后网络 ASP.NET Web应用程序然后键入用户界面然后然后确定



现在您已经创建了UI Wb站点。



如何创建BLL项目?

只需按照说明操作在DAL ...



希望这可以帮助...



不要忘记投票如果有帮助。最高票数为5.



问候,
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,


您好



在2层中创建2个类,一个在DAL中,另一个在BAL中



以下步骤可帮助您将数据绑定到组合框



1)在DAL中创建一个具有返回类型为Datatable的函数的类



示例:



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)在BAL创建一个类

with funtion返回类型为Datatable

示例:





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)最后在Presentation Layer中,组合框存在





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 :-)


这篇关于如何使用DAL,BLL从数据库中读取组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆