|
-
October 23rd, 2008, 03:08 PM
#1
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
-
October 23rd, 2008, 03:57 PM
#2
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
-
October 23rd, 2008, 04:57 PM
#3
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)
)
-
October 24th, 2008, 01:58 PM
#4
Re: Problem : Retrive Data with ref table
-
October 26th, 2008, 04:18 AM
#5
Re: Problem : Retrive Data with ref table
........................... ?
-
October 27th, 2008, 02:11 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|