DataGrid displays "System.Data.DataRow" for a calculated field.

  • Thread starter Thread starter Ben R. Bolton
  • Start date Start date
B

Ben R. Bolton

How does one display a parent field in the Child's dataGrid?



My database has two Tables, Skill, and Category. The Skill.CategoryID
column in the Skill table relates to the Category.ID field in the Category
Table.



The relation was autogenerated from an XSD:

relationCategorySkill = new DataRelation("CategorySkill", new DataColumn[]
{

this.tableCategory.IDColumn}, new DataColumn[] {

this.tableSkill.CategoryIDColumn}, false);



I am attempting to display the Skill Table in a DataGrid but instead of the
CategoryID (an int) I want to display the Category as a string. To my typed
Dataset I added a calculated column as follows:



private void AddCalculatedCategory()

{

if (jetSkillWithCategory_ds1.Skill.Columns.Contains(

Default.Name.CalculatedCategory))

return; //don't create it if it is already there.



jetSkillWithCategory_ds1.Skill.Columns.Add(

Default.Name.CalculatedCategory,

typeof(string),

"Parent.Name");

}



Unfortunately in the DataGrid I typically (not always!) get
"System.Data.DataRow" displayed in 1 or more of the rows.



Why is this happening?

Is there a better way to display the string representation in lieu of the
int?



Any help would be appreciated.



Ben
 
Hi Ben,

Based on my understanding, there are some rows which displays
"System.Data.DataRow" in that column in the child table, when you try to
create a column with a relationship expression. If some rows displays the
correct data, while some rows don't, there seems to be some thing wrong
with the data source. Would you please try to replace some data which
cannot be displayed correctly with correctly displayed data? We can try to
isolate the problem with that.

Generally, there are many ways to join two tables. Besides using a
relationship expression, we can also design a datatable with the additional
column and fill that table with a SQL statement like the following:

SELECT Skill.*, Category.Name FROM Skill LEFT JOIN Category ON
Skill.CategoryID = Category.ID

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin,

Yes some data displays correctly and some doesnt:

Skill CategoryID CalculatedCategoryName
Swimming 2 System.Data.DataRow
Water rafting 2 Athletic Programs
Programming 1 Academic Programs
Engineering 1 Academic Programs


The Category Table is

ID Name
1 Athletic Programs
2 Academic Programs


Changing the CalculatedCategoryName cannot be dont directly since it is a
calculated column.
Changing the CategoryID for Swimming to 1 does not change the
CalculatedCategoryName.
Changing the CategoryID for any other Skill cause causes the
CalculatedCategoryName for that skill to become System.Data.DataRow.


I know that I can use a join. I am trying to determine how calculated
fields work (or in this case why they don't work) when specifiying Parent.


Ben
 
As a Microsoft development partner and Enterprise MSDN subscriber I was
understanding this forum is my avenue for getting support with a 48 hour
response time. It has been more than a week since I replied to your last
post and you still haven't provied any new information. This is an issue I
would like to resolve.

Ben
 
Hello Ben,

Sorry for the late response. It seems that this issue information is lost
in our internal database and so we wasn't able to track the status of it. I
apologize for any inconverience that brought to you and your team.
Currently I am finding an engineer to follow up you here as soon as
possible.

Also, you could create a no spam alias at
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn and use it in the community. In this way, we could send your post
notify email and you could contact us through a feedback email easily.

If you have any more concerns on it, please feel free to post here. Thanks
very much for your understanding.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Ben,

From the code, we cannot see anything that is incorrect. Generally, when
troubleshooting this kind of issues, we can set a breakpoint in the code
and use watch window to monitor the value to see if the binding works. If
that still doesn't work, would you please send me your project and database
file, so that I can debug on it more quickly?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi,

Remove "online" from the email address above is my real email.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi

I'm currently researching on this issue and will update you as soon as I
get any progress.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Ben,

I've done some research on your project. And found that there's no problem
with the data binding on the datagrid. However, the error was related to
the data binding on the combobox named "SkillCategory_combo". The original
binding was:

this.SkillCategory_combo.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedItem", this.jetSkillWithCategory_ds1,
"Category.Name"));
this.SkillCategory_combo.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue",
this.jetSkillWithCategory_ds1, "Skill.CategoryID"));

There's something wrong with the first line. It has to be "SelectedText",
not "SelectedItem". However, we only need to bind one property. Either
SelectedValue or SelectedText. It is recommended to bind the SelectedValue,
because value is usually unique. So if we remove the first line and do some
adjustment with the following settings of the property. The project will be
working as we expected. Here's the adjusted code. I've also changed the
data source and display member. I'll send you the project by email.

this.SkillCategory_combo.DataBindings.Add(new
System.Windows.Forms.Binding("SelectedValue",
this.jetSkillWithCategory_ds1, "Skill.CategoryID"));
this.SkillCategory_combo.DataSource = this.jetSkillWithCategory_ds1;
this.SkillCategory_combo.DisplayMember = "Category.Name";
this.SkillCategory_combo.Location = new System.Drawing.Point(232, 160);
this.SkillCategory_combo.Name = "SkillCategory_combo";
this.SkillCategory_combo.Size = new System.Drawing.Size(121, 21);
this.SkillCategory_combo.TabIndex = 2;
this.SkillCategory_combo.ValueMember = "Category.ID";
this.SkillCategory_combo.Validated += new
System.EventHandler(this.BoundControl_Validated);

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top