Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Get and retrive data using n-tire asp.net


hi everybody i have made n tire to make insert , update , select and delete

insert and delete works fine but i have problem to make select all data in order to make update

this is a method in db.class where connection can be perform
C#
public void ConnectDB(CommandType CT,string ProNameSQl)
    {
        cn = new SqlConnection("Data Source=.;Initial Catalog=Conversation;Integrated Security=True");
        cmd = new SqlCommand();

        cmd.Connection = cn;
        cmd.CommandType = CT;
        cmd.CommandText = ProNameSQl;
        cn.Open();
    }
 
    public int RunProcedure(string ProcedureName, SortedList Paraval)
    {
        ConnectDB(CommandType.StoredProcedure, ProcedureName);

        for (int x = 0; x < Paraval.Count; x++)
        {
            try
            {

                cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(), Paraval.GetByIndex(x));
            }
            catch
            {
                ;
            }
        }
        return ExceNoneQuery();
    }
 public DataTable RunSQl(string Select)
    {
        ConnectDB(CommandType.Text, Select);

        dt=new DataTable();
        dt.Load(cmd.ExecuteReader());
        cn.Close();
        return dt;
    }


and then after check i make another class to pass the type of operation "i" refers to procdure name in sql
C#
public bool Add()
   {
       return LoadProperties2List("i");
   }

if every thing ok it runs to the last tire where the code can perform like insert

C#
public class UsersInfo :MainTable
{
    #region Feild
    private string _id;
    private string _username;
    private string _SecondarySchool;
    private string _University;
  
    #endregion

    #region Properties

    public string id
    {
        get
        {
            return _id;
        }
        set
        {
            _id = value;
        }
    }

    public string UserName
    {
        get
        {
            return _username;
        }
        set
        {
            _username = value;
        }
    }

    public string SecondarySchool
    {
        get
        {
            return _SecondarySchool;
        }
        set
        {
            _SecondarySchool = value;
        }
    }

    public string University
    {
        get
        {
            return _University;
        }
        set
        {
            _University = value;
        }
    }

  

  
    #endregion

    public override bool LoadProperties2List(string TypeOfOperation)
    {
        SortedList Sl = new SortedList();
       
        Sl.Add("@CommandType", TypeOfOperation);
        Sl.Add("@UserName",UserName);
        Sl.Add("@SecondarySchool",SecondarySchool);
        Sl.Add("@University",University);
       

        ProcedureName = "MangeUserInfo";
        if (db.RunProcedure(ProcedureName, Sl) == 1)
            return true;
        else
            return false;

    }

    public bool Register(string User, string SecondaryS, string Unvi)
    {
        this.UserName = User;
        this.SecondarySchool = SecondaryS;
        this.University = Unvi;
      

        if (Add())
            return true;
        else
            return false;
    }



this code works fine how to use these layers to sellect and retrive database and show them in textboxes ??? using the same layers
Posted

thankx all i do my best to solve my problem
i do like this example
public bool find(string usernameid)
{
string query = String.Format("SELECT id FROM Users WHERE UserName='{0}'", usernameid);
DataTable tbl = SeectData(query);
if (tbl.Rows.Count == 0)
return false;
else
{
this.id = tbl.Rows[0][0].ToString();

return true;
}

}

and then call it in page load

if (SelD.find(username))
{
UserNid = SelD.id;
}
now i try it in my code it works fine thanks all
 
Share this answer
 
use object layer,data layer,business logic layer and presentation layer for n-tier architechture
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900