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; }
and here 's methodCode: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; } } }
Stored procedureCode: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; }
Code:create PROCEDURE dbo.StoredProcedure2 AS SELECT StudentInfo.*, Catgerories.Catgname FROM Catgerories INNER JOIN StudentInfo ON Catgerories.CatgId = StudentInfo.CatgId RETURN




Reply With Quote