Click here to Skip to main content
12,750,191 members (37,237 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Sir

My name is hemanth fresher learnig microsoft asp.net.
i have a doubt
here my intention is to insert data into database using 3tier architecture and display that in a grid view in the same page.
in my frontend i have admission no,gender,student name,mobilenumber fields.

i have added the dal and write the code like

namespace Dal
{
public class clsdataaccesslayer
{
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
private void Registration()
{
SqlCommand Cmd = new SqlCommand("dbo.Sp_Registration", Con);
Con.Open();
Cmd.CommandType = CommandType.StoredProcedure;
try
{
Cmd.Parameters.AddWithValue("@P1",TextBox)
// Here How to add the parameters?
}

and in my business access layer i hage written the code like
using Dal;
using System.Data;
namespace Bal
{
    public class Businessaccesslayer
    {
       int Adno;
       string Sname, Gender, Mno;
       clsdataaccesslayer objdal = new clsdataaccesslayer();
       public int PAdno
       {
           set { Adno = value; }
           get { return Adno; }
       }
       public string PSname
       {
           set { Sname = value; }
           get { return Sname; }
       }
       public string PGender
       {
           set { Gender = value; }
           get { return Gender; }
       }
       public string PMno
       {
           set { Mno = value; }
           get { return Mno; }
       }

     }

Please Help me out
Thanks and Regards
Posted 9-Dec-13 23:08pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You should pass the values through entity fields(instead of UI controls), like below

Entity
public class EmployeeInfo
    {
       public string EmployeeName
       {
           set { EmployeeName = value; }
           get { return EmployeeName; }
       }
}

UI
EmployeeInfo eInfo = new EmployeeInfo();
    eInfo.EmployeeName = ((TextBox)gvEG.Rows[e.RowIndex].FindControl("txtEmployeeName")).Text;

DAL(See the bold text)
public class clsdataaccesslayer
{
SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());

private void Registration(EmployeeInfo eInfo)
{
SqlCommand Cmd = new SqlCommand("dbo.Sp_Registration", Con);
Con.Open();
Cmd.CommandType = CommandType.StoredProcedure;
try
{
Cmd.Parameters.AddWithValue("@EmployeeName",eInfo.EmployeeName)
// Here How to add the parameters?
}

Check this article for reference
Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and Framework as 2.0 / 3.0 / 3.5 / 4.0 (VS 2005/2008/2010)[^]
  Permalink  
Comments
raxhemanth 10-Dec-13 5:16am
   
thankyou sir
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Go through this links
Which will help you lot
Understand 3- Tier Architecture in C#[^]
3-tier architecture in C#[^]
  Permalink  
Comments
raxhemanth 10-Dec-13 5:15am
   
thankyou sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 10 Dec 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100