How to pass textbox values from PL to DAL through Business Layer? [Resolved]

Posted by Thiru under ASP.NET on 10/11/2011 | Points: 10 | Views : 2629 | Status : [Member] | Replies : 5
Hi all,
I tried to do N-Tier application.

My Question is:
How to send textbox value to DAL when click the submit-button ?
( i understand that i need to have a business layer to validate and from there i have to pass the values to DAL)

i need to know how to pass the parameter values to DAL from PL through Business layer
Can any one help me to get an idea - please?


As in Presentation Layer - i just created the form but not coding:
   <div style="border:solid 1px gray; width:500px; height:400px">
<table>
<tr><td>Customer Name</td><td><asp:TextBox ID="txtcstnm" runat="server"></asp:TextBox></td></tr>
<tr><td>Customer City</td><td><asp:TextBox ID="txtcstcity" runat="server"></asp:TextBox></td></tr>
<tr><td></td><td><asp:Button ID="btncreatecustomer" runat="server" Text="Create" /></td></tr>
</table>
</div>


coding of DAL is:
Imports System.Data
Imports MySql.Data.MySqlClient
Namespace InvDataLayer
Public MustInherit Class mysqlconn_sampledb
Public dbconn As MySqlConnection = New MySqlConnection("Server=localhost; database=sampledb; userid=root; password=xxxxx; port=3307;")
End Class
End Namespace
Public Class invoiceDAL
Inherits InvDataLayer.mysqlconn_sampledb

Public Function clsInsertCustomer(ByVal objDB As InvDataLayer.mysqlconn_sampledb)
Try
Dim cmd As MySqlCommand
Dim c1 As MySqlConnection
c1 = objDB.dbconn
c1.Open()
cmd = New MySqlCommand("sp_insertcustomer", c1)
'cmd.Parameters.Add("p_cstnm")
cmd.CommandType = CommandType.StoredProcedure
cmd.ExecuteNonQuery()
c1.Close()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.OkOnly, "Error found")
End Try
Return Nothing
End Function
End Class



Stored Procedure is:
DELIMITER $$

DROP PROCEDURE IF EXISTS `sampledb`.`sp_insertcustomer` $$
CREATE PROCEDURE `sampledb`.`sp_insertcustomer`
(
IN p_cstnm varchar(100),
IN p_cstcity varchar(50)
)

BEGIN
INSERT INTO tblcustomer
(cstnm,cstcity) VALUES(p_cstnm,p_cstcity);

END $$

DELIMITER ;





Responses

Posted by: Vuyiswamb on: 10/12/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 50

Up
0
Down

Resolved
hi Thiru

Your button "btncreatecustomer" must have a click event , when the button is clicked the

eish i am not used to the vb example , but i will try to give you a correct

Dim obj As New mysqlconn_sampledb()


Dim model As New InvDataLayer()
model.cstnm = txtcstnm.text
model.cstcity = txtcstcity.text

obj.clsInsertCustomer(model)


//this is how to pass the Value from the presentation layer to the DataLayer. This is just a simple rough way to do it. i am not sure what are the object that you created and your stored procedure has a parameter but the value is never passed to the parameter.

If this is still a problem , when you come online i will team view and help.



Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: SheoNarayan on: 10/11/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Thiru,

Have you read this article http://www.dotnetfunda.com/articles/article18.aspx or http://www.dotnetfunda.com/articles/article71.aspx article?

It has explanations on how to do this.

If you are facing problem in understanding this video, watch this video http://www.myfunda.net/tutorials/itfc/3-TierArchitecture-Video.zip (You need to download & Install Microsoft Live meeting in order to watch this).

Thanks


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

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

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

Up
0
Down
Hi Sir,
Thanks for your valuable reply
i didn't read this before.
hope it will help me - i will try and get back to you.

Thanks for your reply.

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

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

Up
0
Down

Thanks for spending your valuable time on Team Viewer to get me a solution.

code we used in button click event is:
 Dim obj As DataLayer.DataLayer.invoiceDAL = New DataLayer.DataLayer.invoiceDAL()

obj.clsInsertCustomer(txtcstnm.Text, txtcstcity.Text)


Thanks Vuyiswa - thanks a lot.

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

Posted by: Vuyiswamb on: 10/12/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Welcome

Thank you for posting at Dotnetfunda
[Administrator]

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

Login to post response