Return Dataset to Business Layer & SHOW in datagrid in Presentation Layer
-
hi how i can return dataset to datagriedview My business layer is memberBL Class My Data Access Layer Is memberDA Class My view Dataset Code in memberDL Class is:
public DataSet View(memberBL member)
{
DataSet ds = null;try { OpenCnn(); String selectStr = "select \* from " + thisTable + "'"; OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn); ds = new DataSet(); da.Fill(ds, thisTable); CloseCnn(); } catch (Exception e) { String Str = e.Message; } return ds; }
How I Can return Dataset in GriedView in Form? hoW i can use in ds IN windows FORM?
-
hi how i can return dataset to datagriedview My business layer is memberBL Class My Data Access Layer Is memberDA Class My view Dataset Code in memberDL Class is:
public DataSet View(memberBL member)
{
DataSet ds = null;try { OpenCnn(); String selectStr = "select \* from " + thisTable + "'"; OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn); ds = new DataSet(); da.Fill(ds, thisTable); CloseCnn(); } catch (Exception e) { String Str = e.Message; } return ds; }
How I Can return Dataset in GriedView in Form? hoW i can use in ds IN windows FORM?
program is layering & ds in not known in form first ds come in business layer then view in datagried it is not easy my dear friend:confused:
-
program is layering & ds in not known in form first ds come in business layer then view in datagried it is not easy my dear friend:confused:
-
I'm sorry I don't understand. what do you mean by "ds in not known in form"? An by this "first ds come in business layer then view in datagried"? Do you have problem returnig the dataset from your bussines layer to your UI?
yes first ds to business layer then view in UI layer & form
-
yes first ds to business layer then view in UI layer & form
I got that from your anteriour posts. But what is your problem? Passing data from the BLogic to the UI or just the UI part? [EDIT] OK suppose that your UI is in the MyUI namespace. The BussinessLayer is in the MyLogic namespace. in order to populate your UI with data do something like this inside a click event for example:
private void btn1_Click(object sender, EventArgs null){
dataGridView1.DataSource = MyLogic.MemberBL.GetDataSet().Tables[0];
//where the GetDataSet() returns the ds from the BussinessLayer;
}Just like d@nish said if on a different project/dll just add a reference to it.
-
hi how i can return dataset to datagriedview My business layer is memberBL Class My Data Access Layer Is memberDA Class My view Dataset Code in memberDL Class is:
public DataSet View(memberBL member)
{
DataSet ds = null;try { OpenCnn(); String selectStr = "select \* from " + thisTable + "'"; OleDbDataAdapter da =new OleDbDataAdapter(selectStr, cnn); ds = new DataSet(); da.Fill(ds, thisTable); CloseCnn(); } catch (Exception e) { String Str = e.Message; } return ds; }
How I Can return Dataset in GriedView in Form? hoW i can use in ds IN windows FORM?
-
I got that from your anteriour posts. But what is your problem? Passing data from the BLogic to the UI or just the UI part? [EDIT] OK suppose that your UI is in the MyUI namespace. The BussinessLayer is in the MyLogic namespace. in order to populate your UI with data do something like this inside a click event for example:
private void btn1_Click(object sender, EventArgs null){
dataGridView1.DataSource = MyLogic.MemberBL.GetDataSet().Tables[0];
//where the GetDataSet() returns the ds from the BussinessLayer;
}Just like d@nish said if on a different project/dll just add a reference to it.
my business layer is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Library_Project { class memberBL { //Book properties private String membercode; private String name; private String family; private String shsh; private String melicode; private String tavalod; private String shoghl; private String tel; private String mobile; private String adr; private String trkhozv; private memberDA memberData; // BUSINESS LOGIC Member public memberBL() { //Data access layer! memberData = new memberDA(); } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String DatasetData { get { return this.DatasetData; } set { this.DatasetData = value; } } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String Membercode { get { return this.membercode; } set { this.membercode = value; } } /// <SUMMARY> /// Property BooktName (String) /// </SUMMARY> public String Name { get { return this.name; } set { try { this.name = value; if (this.name == "") { throw new Exception( "لطفا نام عضو را وارد نمایید"); } } catch(Exception e) { throw new Exception(e.Message.ToString()); } } } /// <SUMMARY> /// Property ISBN (String) /// </SUMMARY> public String Familly {
-
If everything is in same project, create an instance of your BL class and then call the method which returns the dataset. If BL is in separate project, add a reference to that project in your UI project and then do the same.
My Business Lyaer Is:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;
using System.Data;namespace Library_Project
{
class memberBL
{
//Book properties
private String membercode;
private String name;
private String family;
private String shsh;
private String melicode;
private String tavalod;
private String shoghl;
private String tel;
private String mobile;
private String adr;
private String trkhozv;private memberDA memberData; // BUSINESS LOGIC Member public memberBL() { //Data access layer! memberData = new memberDA(); } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String Membercode { get { return this.membercode; } set { this.membercode = value; } } /// <SUMMARY> /// Property BooktName (String) /// </SUMMARY> public String Name { get { return this.name; } set { try { this.name = value; if (this.name == "") { throw new Exception( "لطفا نام عضو را وارد نمایید"); } } catch(Exception e) { throw new Exception(e.Message.ToString()); } } } /// <SUMMARY> /// Property ISBN (String) /// </SUMMARY> public String Familly { get { return this.family; } set { //could be more checkings here eg revmove ' chars //change to proper case /
-
My Business Lyaer Is:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Text;
using System.Data;namespace Library_Project
{
class memberBL
{
//Book properties
private String membercode;
private String name;
private String family;
private String shsh;
private String melicode;
private String tavalod;
private String shoghl;
private String tel;
private String mobile;
private String adr;
private String trkhozv;private memberDA memberData; // BUSINESS LOGIC Member public memberBL() { //Data access layer! memberData = new memberDA(); } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String Membercode { get { return this.membercode; } set { this.membercode = value; } } /// <SUMMARY> /// Property BooktName (String) /// </SUMMARY> public String Name { get { return this.name; } set { try { this.name = value; if (this.name == "") { throw new Exception( "لطفا نام عضو را وارد نمایید"); } } catch(Exception e) { throw new Exception(e.Message.ToString()); } } } /// <SUMMARY> /// Property ISBN (String) /// </SUMMARY> public String Familly { get { return this.family; } set { //could be more checkings here eg revmove ' chars //change to proper case /
How ds trasnsfer to Business Layer & Then View in form? BUSINESS LAYER & DATA LAYER CODE IS above
-
my business layer is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Library_Project { class memberBL { //Book properties private String membercode; private String name; private String family; private String shsh; private String melicode; private String tavalod; private String shoghl; private String tel; private String mobile; private String adr; private String trkhozv; private memberDA memberData; // BUSINESS LOGIC Member public memberBL() { //Data access layer! memberData = new memberDA(); } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String DatasetData { get { return this.DatasetData; } set { this.DatasetData = value; } } /// <SUMMARY> /// Property BookCode (String) /// </SUMMARY> public String Membercode { get { return this.membercode; } set { this.membercode = value; } } /// <SUMMARY> /// Property BooktName (String) /// </SUMMARY> public String Name { get { return this.name; } set { try { this.name = value; if (this.name == "") { throw new Exception( "لطفا نام عضو را وارد نمایید"); } } catch(Exception e) { throw new Exception(e.Message.ToString()); } } } /// <SUMMARY> /// Property ISBN (String) /// </SUMMARY> public String Familly {
Somthing like this:
//in the business layer create a method or property that gets the
//data from the DataLayer. Something like this:
public DataSet GetDatas(){
return memberData.View();
}//Now in the UI do something like this
LibraryProject.MemberBL bl = new LibraryProject.MemberBL();dataGridView1.DataSource = bl.GetDatas().Tables[0];
[Edit]Fixed pre tags[/EDIT]
modified on Sunday, February 21, 2010 10:58 PM