8 Replies - 3605 Views - Last Post: 14 April 2010 - 08:37 AM Rate Topic: -----

#1 chocus aterguss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-April 09

Calculated columns in type dataset

Posted 12 April 2010 - 01:12 AM

:plain:Hi there;

I'm racking my brains for a while and haven't found the solution for this:

[list=1]
[list]

[*]I'm using VS 2005 and a Type Dataset( WINFORM)
[*]I add two tables (Parent and child) with the proper relation
[*]I add a calculated column in the Parent table with the following expression (Parent.[columnname]).
[*]At run time the calculated column returns a null vale.

I don't really know what's wrong generating calculated columns with Type dataset.
No run-time error just only null vales ...please help.

Is This A Good Question/Topic? 0
  • +

Replies To: Calculated columns in type dataset

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5936
  • View blog
  • Posts: 12,862
  • Joined: 16-October 07

Re: Calculated columns in type dataset

Posted 12 April 2010 - 04:57 AM

Take the "Parent." out. There is no table scope in the declaration. You can't look at other tables.

You can do this:
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Test");
dt.Columns.Add("ColAlpha", typeof(int));
DataColumn dc = dt.Columns.Add("ColBeta", typeof(int));
dc.Expression = "[ColAlpha]";



Not:
dc.Expression = "Test.[ColAlpha]";



More here: http://msdn.microsof...n(v=VS.71).aspx
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Calculated columns in type dataset

Posted 12 April 2010 - 09:14 AM

Moved to C#
Was This Post Helpful? 0
  • +
  • -

#4 chocus aterguss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-April 09

Re: Calculated columns in type dataset

Posted 14 April 2010 - 06:53 AM

Hi There:
I'm using VS 2205 in winForms (C#).I created a strong Type Dataset using the UIE wizard of VS2005. I added a couple of datatables parent-child with their relationship. I put a calculated column in the child table using Expresion= Parent.columnname.
On runtime the dataset return a null calculated column.
In another hand, I have tried another way around by I coding the dataset (untype) and the calculated column works smoothly.

Is it a bug of this version or I'm missing something?
PLEASE HELP !!!!!!
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Calculated columns in type dataset

Posted 14 April 2010 - 07:37 AM

The answer in your previous topic was insufficient?
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Calculated columns in type dataset

Posted 14 April 2010 - 07:42 AM

Topics merged, there's no need for duplicate topics.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_chocus aterguss*


Reputation:

Re: Calculated columns in type dataset

Posted 14 April 2010 - 08:00 AM

Hi baavgai:

Thanks for the prompt reply but I;m still out..please notice that I have two Tableadapter(no one) in the dataset hence I want in the calculated column make reference to the Parent table...if I follow your indication VS compile an error "Cannot find column" in other words I have to prefix Parent. in order to lookup the column that I want in the another table.
There's nothing wrong with adding Parent. because if I changed the column name deliberately and the compiler inmediately pick up the mistaken column ...it means that my approach is correct, BUT I'M STILL DON'T UNDERSTAND WHY RETURN NULL.

Any help will be highly appreciated

awaiting ......



View Postbaavgai, on 12 April 2010 - 03:57 AM, said:

Take the "Parent." out. There is no table scope in the declaration. You can't look at other tables.

You can do this:
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Test");
dt.Columns.Add("ColAlpha", typeof(int));
DataColumn dc = dt.Columns.Add("ColBeta", typeof(int));
dc.Expression = "[ColAlpha]";



Not:
dc.Expression = "Test.[ColAlpha]";



More here: http://msdn.microsof...n(v=VS.71).aspx

Was This Post Helpful? 0

#8 Guest_chocus aterguss*


Reputation:

Re: Calculated columns in type dataset

Posted 14 April 2010 - 08:06 AM

Hi baavgai:

Thanks for the prompt reply but I;m still out..please notice that I have two Tableadapter(no one) in the dataset hence I want in the calculated column make reference to the Parent table...if I follow your indication VS compile an error "Cannot find column" in other words I have to prefix Parent. in order to lookup the column that I want in the another table.
There's nothing wrong with adding Parent. because if I changed the column name deliberately and the compiler inmediately pick up the mistaken column ...it means that my approach is correct, BUT I'M STILL DON'T UNDERSTAND WHY RETURN NULL.

Any help will be highly appreciated

awaiting ......
Was This Post Helpful? 0

#9 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5936
  • View blog
  • Posts: 12,862
  • Joined: 16-October 07

Re: Calculated columns in type dataset

Posted 14 April 2010 - 08:37 AM

Check your relation. Also, the docs are unclear how to handle multiple parents.

Assuming the relation is set correctly, Parent should work.

e.g.
DataSet ds = new DataSet();
DataTable dt1 = ds.Tables.Add("Deparment");
dt1.Columns.Add("DeptId", typeof(int));
dt1.Columns.Add("Description", typeof(string));
dt1.Constraints.Add("PkDepartment", dt1.Columns["DeptId"], true);

DataTable dt2 = ds.Tables.Add("Employee");
dt2.Columns.Add("EmpId", typeof(int));
dt2.Columns.Add("DeptId", typeof(int));
dt2.Columns.Add("FullName", typeof(string));
dt2.Columns.Add("DepartmentName", typeof(string));
dt2.Constraints.Add("PkEmployee", dt2.Columns["EmpId"], true);

ds.Relations.Add(dt1.Columns["DeptId"], dt2.Columns["DeptId"]);
dt2.Columns["DepartmentName"].Expression = "Parent.Description";

dt1.Rows.Add(1, "Finance");
dt1.Rows.Add(2, "IT");
dt2.Rows.Add(1, 2, "Baavgai");

System.Diagnostics.Debug.WriteLine(ds.GetXml());



Results:
<NewDataSet>
  <Deparment>
    <DeptId>1</DeptId>
    <Description>Finance</Description>
  </Deparment>
  <Deparment>
    <DeptId>2</DeptId>
    <Description>IT</Description>
  </Deparment>
  <Employee>
    <EmpId>1</EmpId>
    <DeptId>2</DeptId>
    <FullName>Baavgai</FullName>
    <DepartmentName>IT</DepartmentName>
  </Employee>
</NewDataSet>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1