Click here to Skip to main content
15,886,919 members
Home / Discussions / Database
   

Database

 
AnswerRe: How to Check Existing Record first then Insert otherwise update statement Pin
Blue_Boy28-Oct-08 0:20
Blue_Boy28-Oct-08 0:20 
AnswerRe: How to Check Existing Record first then Insert otherwise update statement Pin
Tim Carmichael28-Oct-08 2:02
Tim Carmichael28-Oct-08 2:02 
QuestionCopying data in one table to specific fields in another table Pin
Member 365120927-Oct-08 1:22
Member 365120927-Oct-08 1:22 
AnswerRe: Copying data in one table to specific fields in another table Pin
Wendelius27-Oct-08 10:00
mentorWendelius27-Oct-08 10:00 
QuestionError:The cursor does not include the table being modified or the table is not updatable through the cursor Pin
V K 226-Oct-08 19:19
V K 226-Oct-08 19:19 
AnswerCross-post (3/3) Pin
Wendelius27-Oct-08 9:21
mentorWendelius27-Oct-08 9:21 
AnswerCP IGNORE THIS USER Pin
leckey27-Oct-08 10:00
leckey27-Oct-08 10:00 
QuestionProblem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 1:14
Ahmed R El Bohoty26-Oct-08 1:14 
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.


Tables
Create Table Catgerories (
CatgId int PRIMARY KEY,
Catgname nvarchar(50)
)


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


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


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; }
    }
}



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; }
    }
}



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;
    }

AnswerRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 1:34
mentorWendelius26-Oct-08 1:34 
QuestionRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 1:53
Ahmed R El Bohoty26-Oct-08 1:53 
AnswerRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 2:06
mentorWendelius26-Oct-08 2:06 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 4:21
Ahmed R El Bohoty26-Oct-08 4:21 
GeneralRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 5:28
mentorWendelius26-Oct-08 5:28 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 8:15
Ahmed R El Bohoty26-Oct-08 8:15 
GeneralRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 8:23
mentorWendelius26-Oct-08 8:23 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 8:25
Ahmed R El Bohoty26-Oct-08 8:25 
GeneralRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 8:33
mentorWendelius26-Oct-08 8:33 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 8:47
Ahmed R El Bohoty26-Oct-08 8:47 
GeneralRe: Problem : Retrive Data with ref table Pin
Wendelius26-Oct-08 10:59
mentorWendelius26-Oct-08 10:59 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty26-Oct-08 13:25
Ahmed R El Bohoty26-Oct-08 13:25 
GeneralRe: Problem : Retrive Data with ref table Pin
Wendelius27-Oct-08 9:10
mentorWendelius27-Oct-08 9:10 
AnswerRe: Problem : Retrive Data with ref table Pin
Rami Said Abd Alhalim27-Oct-08 2:20
Rami Said Abd Alhalim27-Oct-08 2:20 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty27-Oct-08 2:23
Ahmed R El Bohoty27-Oct-08 2:23 
GeneralRe: Problem : Retrive Data with ref table Pin
Rami Said Abd Alhalim27-Oct-08 3:13
Rami Said Abd Alhalim27-Oct-08 3:13 
GeneralRe: Problem : Retrive Data with ref table Pin
Ahmed R El Bohoty27-Oct-08 3:19
Ahmed R El Bohoty27-Oct-08 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.