Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I added the following code in the data access layer. How to call that method in UI layer?

public class TutorRegistratonDAL
{
        SqlConnection con = new SqlConnection();
        SqlTransaction tr = new SqlTransaction();
        
        public DataSet Inserttutor(DataSet ds_sub,DataSet ds_lang,DataSet ds_time)
        {
            con.ConnectionString = StrCon;

            try
            {
                con.Open();
                SqlBulkCopy sub_copy = new SqlBulkCopy(con);
                sub_copy.DestinationTableName = "tutor_subjects";
                DataTable sub_dt = new DataTable();
                sub_dt= ds_sub.Tables[0];
                sub_copy.WriteToServer(sub_dt);
                SqlBulkCopy lang_copy = new SqlBulkCopy(con);
                lang_copy.DestinationTableName = "tutor_languages";
                DataTable lang_dt = new DataTable();
                lang_dt = ds_lang.Tables[0];
                lang_copy.WriteToServer(lang_dt);
                tr.Commit();
                return true;
            }
            catch (Exception ex)
            {
                tr.Rollback();
                return false;
            }
            finally
            {            
                con.Close();
            }
         }
Posted
Updated 8-Apr-10 0:18am
v2

Hi,

I am completly with the above answers, However i am thinking that why would you want to make a call to the Dal from the UI.

Ideally you will make the call to the DAL from UI through the Business logic layer, This acts as the central point of contact for any logic in terms of managing the transactions/logging details etc.

last but not the least, if you introdcue the business logic layer then you will also be able to get the loose coupling between the UI and the data. ie if you use Unity application block then you can replace the dal layer with the new dal,without rebuilging the entire code base..

One more interesting thought is that,if you have the business layer tomorrow you can expose your business component through the services to the other applications, (Re using feature)..

Hence i would suggest you to re look at your strategy...

I hope this helps!.

Regards,
-Vinayak
 
Share this answer
 
In user interface layer call the method like this,

TutorRegistratonDAL tutorRegistratonDAL = new TutorRegistratonDAL();
tutorRegistratonDAL.Inserttutor(pass parameters)
 
Share this answer
 
First you need to add a reference of your Data Layer in your UI App. Then you can create instance of your data layer class.

Ex.
C#
DAL.TutorRegistratonDAL RegDAL=new DAL.TutorRegistratonDAL();
DataSet ds=new DataSet();
ds=RegDAL.Inserttutor(ds_sub,ds_lang,ds_time);
 
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