本文介绍了如何使用DAL,BLL从数据库中读取组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想将此转换为DAL和BLL i want to convert this to DAL andBLLsqlDataReader 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(); }} 推荐答案 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 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 DatatableExample: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从数据库中读取组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 19:21