How to get details from DataLayer to Presentation Layer ? [Resolved]

Posted by Thiru under ASP.NET on 10/21/2011 | Points: 10 | Views : 1738 | Status : [Member] | Replies : 6
Hi Friends,
Let me know how to get details from DataLayer to Presentation Layer ?

I can able to send details as follows:

As in presentation layer
Dim objcalevents As BusinessLayer.BAL.CalanderEventBAL = New BusinessLayer.BAL.CalanderEventBAL
objcalevents.dtp = txtedtp.Text
objcalevents.ttl = txtettl.Text
objcalevents.ewhen = txtetime.Text
objcalevents.ewhere = txteplace.Text
objcalevents.descri = txtdescri.Text
objcalevents.createnewevent()

As in business layer:
Public Function createnewevent()
Dim objevent As DataLayer.DAL.CalendarEvents = New DataLayer.DAL.CalendarEvents
Return objevent.NewCalanderEvent(dtp, ttl, ewhen, ewhere, descri)
End Function

As in Data Layer:
Public Function NewCalanderEvent(ByVal dtp As Date, ByVal ttl As String, ByVal ewhen As String, ByVal ewhere As String, ByVal descri As String)
Dim c1 As MySqlConnection
Dim cmd As MySqlCommand
Dim rtn_rslt = String.Empty
c1 = dbconn
Try
c1.Open()
cmd = New MySqlCommand("sp_createnewevent", c1)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("p_dtp", dtp).Value = dtp
cmd.Parameters.Add("p_ttl", ttl).Value = ttl
cmd.Parameters.Add("p_ewhen", ewhen).Value = ewhen
cmd.Parameters.Add("p_ewhere", ewhere).Value = ewhere
cmd.Parameters.Add("p_descri", descri).Value = descri
cmd.Parameters.Add(New MySqlParameter("p_result", MySqlDbType.Int16))
cmd.Parameters("p_result").Direction = ParameterDirection.Output
rtn_rslt = "Successfully Saved"
cmd.ExecuteNonQuery()
c1.Close()
Catch ex As Exception
End Try
Return rtn_rslt
End Function


But how to GET DETAILS FROM DATALAYER TO PRESENTATION LAYER:
NEED TO GET THE FOLLOWING DETAILS IN PRESENTATION LAYER THROUGH BAL FROM DAL:
        txtedtp.Text = ?
txtettl.Text = ?
txtetime.Text = ?
txteplace.Text = ?
txtdescri.Text = ?


Expecting your valuable reply.
regards,
Thiru.




Responses

Posted by: SheoNarayan on: 10/21/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Hi Thiru,

Have a look at the response of this post http://www.dotnetfunda.com/forums/thread5525-teir-3-programming-style-with-example.aspx. Download the recording from myfunda.net and watch it, it should give you enough understanding.

Read below articles as well
http://www.dotnetfunda.com/articles/article71.aspx
http://www.dotnetfunda.com/articles/article18.aspx

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 10/24/2011 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Ya Thiru,

We can create a object of DAL -> BAL then BAL -> PL.
I forgot, you are using 3- Tier.

Thanks,
T.Saravanan

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 10/23/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply Mr.Sheo Narayan.
Its a fantastic article - actually i created the sample application with reference of your 3T,4T article.

I understand and learn to pass variables from PL to DAL through BAL and do required operations in DB too.
But i am standing here to know about the way we can get required details by passing an ID from PL to DAL.

I have mentioned clearly in the previous post too that is:


How to GET DETAILS FROM DATALAYER TO PRESENTATION LAYER :
NEED TO GET THE FOLLOWING DETAILS IN PRESENTATION LAYER THROUGH BAL FROM DAL:
txtedtp.Text = ?


txtettl.Text = ?

txtetime.Text = ?

txteplace.Text = ?

txtdescri.Text = ?


As i told, i understand to pass the above text values from PL to DAL to do operations in DB
but when i want to display details about particular event (eg: to get details of particular customer using/passing customer ID)

i understand to pass the ID from PL to DAL and execute (like: "select * from tbl where id=xxx")
in this case how can i return the details of that ID back to PL to display ?

expecting your valuable reply

Regards,
Thiru.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 10/23/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Thiru,

Just consider in your DAL the method return type is 'DataTable'...
refer the below code...

In your DAL...

public DataTable GetDetails(int nId)
{
SqlConnection sqlcon =....
// Your code..
// If you using dataadapter means...
DataTable dtResult = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from tbl where id="+nId,sqlcon);
da.Fill(dtResult);
return dtResult;
}


In your PL

private void FillDetails()
{
//Consider testDAL is your DAL class object.
DataTable dtResult = testDAL.GetDetails(1);
if(dtResult.Rows.Count > 0)
{
txtedtp.Text = dtResult.Rows[0]["edtp"].ToString();
txtettl.Text = dtResult.Rows[0]["ettl"].ToString();
txtetime.Text = dtResult.Rows[0]["etime"].ToString();
txteplace.Text = dtResult.Rows[0]["eplace"].ToString();
txtdescri.Text = dtResult.Rows[0]["descri"].ToString();
}
}


Its helpful to you...

Thanks,
T.Saravanan

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 10/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Saravanan,
Thanks for your reply.

As in your code above: PL under FillDetails()
you suggested me to use testDAL class object in PL

I agree, Its fine and will work too.
But i heard that a rule in 3Tier -- we should not have a direct communication from PL to DAL
It should be only through BL right ?
if so, how can we do the above same code through BL (DAL - BL - PL)

I hope we should create a object class in BL for filldetails and this shlould be referred in PL -- AM I RIGHT ?
expecting your valuable reply.
Regards,
Thiru.


Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 10/25/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply Saravanan :-)

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response