CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    122

    Problem : Retrive Data with ref table

    hi ,
    i make simple method that retrieve data from tables this is easy but my problem happen when i retrieve data from table that have relationship with other table, i make class to set value into properties when i read and bind it in Gridview.

    i make for each table class that contains to properties and if i make all table in one class it work so i want to find solution to it with do this.
    Code:
    public class CatgBL
    {
        int cid = 0;
    
        public int Cid
        {
            get { return cid; }
            set { cid = value; }
        }
        string catgName;
    
        public string CatgName
        {
            get { return catgName; }
            set { catgName = value; }

    Code:
    public class MyStudent
    {
        int stid;
    
        public int Stid
        {
            get { return stid; }
            set { stid = value; }
        }
        string sname;
    
        public string Sname
        {
            get { return sname; }
            set { sname = value; }
        }
        int catgid;
    
        public int Catgid
        {
            get { return catgid; }
            set { catgid = value; }
        }
    }
    and here 's method

    Code:
      SqlConnection myCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator\My Documents\TestDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
        public ArrayList RetriveStdentInfo()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = myCon;
            cmd.CommandText = "dbo.StoredProcedure2";
            cmd.CommandType = CommandType.StoredProcedure;
            //cmd.Parameters=ParameterDirection.ReturnValue;
            myCon.Open();
            IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    
            ArrayList sequence = new ArrayList();
            ArrayList seqCat = new ArrayList();
            ArrayList seqStudent = new ArrayList();
            while (reader.Read())
            {
                MyStudent std = new MyStudent();
                CatgBL cat = new CatgBL();
                std.Stid = reader.GetInt32(0);
                std.Sname = reader.GetString(reader.GetOrdinal("stname"));
                std.Catgid = reader.GetInt32(reader.GetOrdinal("Catgid"));
                cat.CatgName = reader.GetString(reader.GetOrdinal("CatgName"));
                seqCat.Add(cat);
                seqStudent.Add(std);
                sequence.AddRange(seqStudent);
                sequence.AddRange(seqCat);
            }
            return sequence;
        }
    Stored procedure

    Code:
    create PROCEDURE dbo.StoredProcedure2 
    AS
    	SELECT     StudentInfo.*, Catgerories.Catgname
    FROM         Catgerories INNER JOIN
                          StudentInfo ON Catgerories.CatgId = StudentInfo.CatgId
    	RETURN

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Problem : Retrive Data with ref table

    There are NO tables anywhere in your posted code......
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Feb 2007
    Posts
    122

    Re: Problem : Retrive Data with ref table

    Tables :

    Code:
    Create Table Catgerories (
    CatgId int PRIMARY KEY,
    Catgname nvarchar(50)
    )
    Code:
    Create Table StudentInfo(
    stId int PRIMARY KEY,
    Stname nvarchar(50),
    CatgId int  REFERENCES Catgerories (CatgId)
    )

  4. #4
    Join Date
    Feb 2007
    Posts
    122

    Re: Problem : Retrive Data with ref table

    ?????????????

  5. #5
    Join Date
    Oct 2006
    Posts
    123

    Re: Problem : Retrive Data with ref table

    ........................... ?

  6. #6
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Resolved Re: Problem : Retrive Data with ref table

    look at this , They display Data from a Join

    http://www.codeproject.com/KB/cs/N-Tier22.aspx

    Hope it helps
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured