Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Presentation Layer Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;

namespace _3_tiersample
{
public partial class RegistrationForm : System.Web.UI.Page
{
classBLL Objbal = new classBLL();
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
string Output = string.Empty;
classBLL Objbalregistration = new classBLL();
Objbalregistration.Name = TextBox1.Text;
Objbalregistration.Roll_Number = Convert.ToInt32(TextBox2.Text);
Objbalregistration.Email_Id = TextBox3.Text;
Objbalregistration.Mobile_Number = TextBox4.Text;
Objbalregistration.InsertUserDetails(Objbal);//here Iam getting the above error please help me out
Console.WriteLine("Data Inserted");
}
catch(Exception Ex)
{
Console.WriteLine(Ex);
}
}

}
}
Data Access Layer;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BLL;

namespace DAL
{
public class classDAL
{
string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

public void InsertUserDetails(classBLL Objbal)
{
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand("sp_InsertEmpdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
try
{
cmd.Parameters.AddWithValue("@Name", Objbal.Name);
cmd.Parameters.AddWithValue("@Roll_Number", Objbal.Roll_Number);
cmd.Parameters.AddWithValue("@Email_Id", Objbal.Email_Id);
cmd.Parameters.AddWithValue("@Mobile_Number", Objbal.Mobile_Number);
Console.WriteLine( "data saved");
}
catch (Exception Ex)
{
Console.WriteLine(Ex);
}
finally
{
con.Dispose();
}

}

}
}
Business Logic Layer Code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;


namespace BLL
{
    public class classBLL
    {
        private string _Name;
        private int _Roll_Number;
        private string _Email_Id;
        public string _Mobile_Number;


        public string Name
        {
            set { _Name = value; }
            get { return _Name; }
        }
        public int Roll_Number
        {
            set { _Roll_Number = value; }
            get { return _Roll_Number; }
        }
        public string Email_Id
        {
            set { _Email_Id = value; }
            get { return _Email_Id; }
        }
        public string Mobile_Number
        {
            set { _Mobile_Number = value; }
            get { return _Mobile_Number; }
        }

    }
}
Thanks In Advance
Posted

Make the instance of DAL. if you see
InsertUserDetails method is inside DAL
C#
classDAL objClassDAL = new classDAL();
 objClassDAL.InsertUserDetails(Objbalregistration) 
 
Share this answer
 
Change your code as below

C#
protected void Button1_Click(object sender, EventArgs e)
 {
 try
 {
 string Output = string.Empty;

 classDAL objClassDAL = new classDAL();
 classBLL Objbalregistration = new classBLL();

 Objbalregistration.Name = TextBox1.Text;
 Objbalregistration.Roll_Number = Convert.ToInt32(TextBox2.Text);
 Objbalregistration.Email_Id = TextBox3.Text;
 Objbalregistration.Mobile_Number = TextBox4.Text;
 
 objClassDAL.InsertUserDetails(Objbalregistration);
 Console.WriteLine("Data Inserted");
 
 }
 catch(Exception Ex)
 {
 Console.WriteLine(Ex.Message);
 }
 }
 
Share this answer
 

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