Click here to Skip to main content
15,895,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
OriginalGriff25-May-15 20:46
mveOriginalGriff25-May-15 20:46 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Agent__00725-May-15 22:43
professionalAgent__00725-May-15 22:43 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Alan N25-May-15 23:22
Alan N25-May-15 23:22 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Agent__00725-May-15 23:56
professionalAgent__00725-May-15 23:56 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Gyana_Ranjan Dash26-May-15 21:08
Gyana_Ranjan Dash26-May-15 21:08 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Armugam Indrani28-May-15 22:48
professionalArmugam Indrani28-May-15 22:48 
AnswerRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# PinPopular
harold aptroot26-May-15 1:02
harold aptroot26-May-15 1:02 
QuestionDataRelation problem Pin
Supratik De25-May-15 6:35
Supratik De25-May-15 6:35 
Hi,

I have to built one console application in C# and the problem is --
Sample Dataset:

CategoryId ParentCategoryId Name Keywords

100 -1 Business Money

200 -1 Tutoring Teaching

101 100 Accounting Taxes

102 100 Taxation

201 200 Computer

103 101 Corporate Tax

202 201 Operating

109 101 Small business

System

Tax

Write a working program which should do the following:

a. Given a category id return category name, parentCategoryId and key-word. Ensure that if

key-word is not present for the category, then the data from its parent should be

returned.

i. Input: 201; Output: ParentCategoryID=200, Name=Computer,

ii. Input: 202; Output: ParentCategoryID=201, Name=Operating System,

Sample Input/Output:

Keywords=Teaching

Keywords=Teaching

b. Given category level as parameter (say N) return the names of the categories which are

of N’th level in the hierarchy (categories with parentId -1 are at 1st level).

Sample Input/Output:

i. Input: 2; Output: 101, 102, 201

ii. Input: 3; Output: 103, 109, 202

.........................................................


Now my piece of code is ----



static void Main(string[] args)
{

DataSet ds = new DataSet("Category");



// Table for parents

DataTable parentTable = new DataTable("Parents");

//parentTable.Columns.Add("CategoryId", typeof(int));

parentTable.Columns.Add("ParentCategoryId", typeof(int));

parentTable.Columns.Add("Name", typeof(string));

parentTable.Columns.Add("Keywords", typeof(string));

//Create some childs.

parentTable.Rows.Add(new object[] { 100, "Business", "Money" });

parentTable.Rows.Add(new object[] { 200, "Tutoring", "Teaching" });

parentTable.Rows.Add(new object[] { 101,"Accounting", "Taxes" });

//parentTable.Rows.Add(new object[] { 102, 100, "Taxation", "" });

parentTable.Rows.Add(new object[] { 201, "Computer", "" });

//parentTable.Rows.Add(new object[] { 103, 101, "Corporate Tax", "" });

//parentTable.Rows.Add(new object[] { 202, 201, "Operating System", "" });

//parentTable.Rows.Add(new object[] { 109, 101, "Small Business Tax", "" });

ds.Tables.Add(parentTable);





// Table for childrend

DataTable childTable = new DataTable("Child");

childTable.Columns.Add("CategoryId", typeof(int));

childTable.Columns.Add("ParentCategoryId", typeof(int));

childTable.Columns.Add("Name", typeof(string));

childTable.Columns.Add("Keywords", typeof(string));

//Create some childs.

childTable.Rows.Add(new object[] { 100,-1, "Business", "Money" });

childTable.Rows.Add(new object[] { 200,-1, "Tutoring", "Teaching" });

childTable.Rows.Add(new object[] { 101,100, "Accounting", "Taxes" });

childTable.Rows.Add(new object[] { 102,100, "Taxation", "" });

childTable.Rows.Add(new object[] { 201,200, "Computer", "" });

childTable.Rows.Add(new object[] { 103,101, "Corporate Tax","" });

childTable.Rows.Add(new object[] { 202,201, "Operating System", "" });

childTable.Rows.Add(new object[] { 109,101, "Small Business Tax", "" });

ds.Tables.Add(childTable);



// Create their relation.

DataRelation parentChildRelation = new DataRelation("ParentChild",parentTable.Columns["CategoryId"], childTable.Columns["ParentCategoryId"]);

ds.Relations.Add(parentChildRelation);



// Display each parent and their children based on the relation.

string category = null;

category = Console.ReadLine();

for (int i = 0; i < ds.Tables["Child"].Rows.Count; i++)
{

if (category == ds.Tables["Child"].Columns["CategoryId"].ToString())
{

foreach (DataRow parent in parentTable.Rows)
{
DataRow[] children = parent.GetChildRows(parentChildRelation);

Console.WriteLine("\n{0}, has {1} children", parent["ParentName"].ToString(), children.Count<datarow>());

foreach (DataRow child in children)
{

Console.WriteLine("\t{0}", child["ChildName"].ToString());

}
}

}

else
{
Console.WriteLine("\n Enter a valid Category ID :\n");

}
}

}

.............................................................

Questions -

1. I am getting a ArgumentNullException on DataRelation line. The error is "'column' argument cannot be null.
Parameter name: column" - How to solve this.

2. Where I can make a check that Keywords are null.

3. Should I define another DataTable for Level?

Thanks & Regards
Supratik De
AnswerRe: DataRelation problem Pin
Richard Deeming27-May-15 1:19
mveRichard Deeming27-May-15 1:19 
QuestionInterface implementation strategies : four techniques; but: when (if) to use (which) one of them Pin
BillWoodruff25-May-15 4:06
professionalBillWoodruff25-May-15 4:06 
AnswerRe: Interface implementation strategies : four techniques; but: when (if) to use (which) one of them Pin
Richard Deeming27-May-15 1:29
mveRichard Deeming27-May-15 1:29 
QuestionToolstrip grey border Pin
Member 1171517124-May-15 6:52
Member 1171517124-May-15 6:52 
AnswerRe: Toolstrip grey border Pin
Ravi Bhavnani25-May-15 9:53
professionalRavi Bhavnani25-May-15 9:53 
QuestionReport From Date to Date Pin
abdo.kouta23-May-15 5:45
abdo.kouta23-May-15 5:45 
AnswerRe: Report From Date to Date Pin
OriginalGriff23-May-15 6:15
mveOriginalGriff23-May-15 6:15 
GeneralRe: Report From Date to Date Pin
abdo.kouta23-May-15 8:02
abdo.kouta23-May-15 8:02 
AnswerRe: Report From Date to Date Pin
Mycroft Holmes23-May-15 17:22
professionalMycroft Holmes23-May-15 17:22 
QuestionRe: Report From Date to Date Pin
abdo.kouta23-May-15 21:37
abdo.kouta23-May-15 21:37 
AnswerRe: Report From Date to Date Pin
Mycroft Holmes24-May-15 0:28
professionalMycroft Holmes24-May-15 0:28 
GeneralRe: Report From Date to Date Pin
abdo.kouta24-May-15 4:02
abdo.kouta24-May-15 4:02 
GeneralRe: Report From Date to Date Pin
Mycroft Holmes24-May-15 14:16
professionalMycroft Holmes24-May-15 14:16 
AnswerRe: Report From Date to Date Pin
jschell24-May-15 7:01
jschell24-May-15 7:01 
Questionasp.net with c# Pin
Member 1158609823-May-15 0:50
Member 1158609823-May-15 0:50 
AnswerRe: asp.net with c# Pin
Sascha Lefèvre23-May-15 1:18
professionalSascha Lefèvre23-May-15 1:18 
AnswerRe: asp.net with c# Pin
OriginalGriff23-May-15 2:05
mveOriginalGriff23-May-15 2:05 

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.