Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to write For loop in DAL and how to call it in presentation in three tier architecture
Posted
Comments
vangapally Naveen Kumar 4-Sep-14 5:20am    
what is your question ? please elaborate more about question

You cant directly call for loop in a class without having a function. You need to write your loop within a function first as per your requirement.

C#
public class TestDAL
{
 public int YourFunction(int YourInput)
{
//Your For loop as you want

for (int i = 10 - 1; i >= 0; i--)
	{
	    // What you want to do within the for loop
	}
}
}


Then you need to refer the project having DAL Class to your Presentation Layer. You can right click the reference folder and add reference >> select the DAL project from solution

Then you have complete refer your DAL project to the UI.
Go to your class in UI project. import the assembly you referred already. (Included the DAL Class)
Eg:
C#
using YourSolutionName.YourProjectName


Then You can call your DAL class function included your for loop.For that you need to create object of the DAL Class first

eg:
C#
DALClass ObjDAL = new DALClass ();


Then You can call function of DAL

C#
objDAL.YourFunction(int YourInput)


Think you could understood the process.
 
Share this answer
 
Actually I have to written for loop in DAL and it is added to DataGridView in Presentation layer.How to write code for this

Here is the sample code

C#
for (int i = 0; i < Prodcode.Length; i++)
                    {
                        if (cn.State != ConnectionState.Open)
                            cn.Open();
                        cmd.Connection = cn;
                        string value = "";

                        cmd.CommandText = " select  A.[prod_code] [Code],A.[prod_desc] [Desc],invd_uom [UOM],A.invd_qty-A.invd_qty_sent-(select isnull(sum(invd_qty_sent),0) from invoice_details where prod_code='" + Prodcode[i] + "' and comp_id='" + cpnyid + "' and Link_inv_no=B.inv_no) as reserve,B.inv_no as Invoice  from invoice_details AS A" +
                                          " INNER JOIN invoice_master AS B ON A.inv_no=B.inv_no " +
                                          "  WHERE (A.invd_qty-A.invd_qty_sent)>0 AND a.invd_qty_reservePros='false' and A.comp_id='" + cpnyid + "'and B.cust_code= '" + cfs.singlequotconver(txt_Custcode.Text)
                                          + "' and prod_code ='" + Prodcode[i] + "' and b.inv_no='" + Trnno[i] + "'and invd_qty_reserveDone<>'true' and invd_id='" + IdS[i] + "'  union ";
                        cmd.CommandText += "select prod_code [Code],prod_desc [Desc],popr_uom [UOM],convert(decimal(18,0),popr_bqty)-(select isnull(sum(invd_qty_sent),0) from invoice_details where prod_code='" + Prodcode[i] + "' and comp_id='" + cpnyid + "' and Link_inv_no=product_open_balance_reserve.inv_no) as  [reserve],inv_no as Invoice " +
                            " from product_open_balance_reserve where comp_id='" + cpnyid + "' and cust_code='" + cfs.singlequotconver(txt_Custcode.Text) +
                            "' and prod_code ='" + Prodcode[i] + "' and inv_no='" + Trnno[i] + "' and popr_deleted=0 and popr_id='" + IdS[i] + "' ";
                        dr = cmd.ExecuteReader();
                        object[] obj1 = { "", "", "", Properties.Settings.Default.SendBalance.ToString() };
                        if (i == 0)
                        {
                            dataGridViewEx1.Rows.Add(obj1);
                        }
                        while (dr.Read())
                        {
                            object[] obj = { "", dr["Code"].ToString(), "", dr["Desc"].ToString(), "", "", dr["reserve"].ToString(), dr["UOM"].ToString(), "", "", dr["reserve"].ToString(), "", "", "", "", "", "", "", "", "", "", dr["Invoice"].ToString() };
                            dataGridViewEx1.Rows.Add(obj);
                        } dr.Close();

                    }
 
Share this answer
 
Comments
Gihan Liyanage 4-Sep-14 5:42am    
Hello Dear, You might not familiar with code project.. You can use Improve question Widget under your question to update your question. You just post your code in answers section. Any way see my solution. I wrote it by assuming your full question.

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