All,
Writing a simple program to read data from a group of table to display for order entry. IN trying to get the data fromt he related table in this code:
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Linq;using
System.Text;using
System.Windows.Forms;using
System.Data.Sql;using
System.Data.SqlClient;using
Xceed.SmartUI.Controls.TreeView;namespace
Pareto_OE{
public partial class frmOrderRequest : Form{
private bool m_ExitOnLoad = false;SqlConnection connParetodb = new SqlConnection("Data Source=REM-1726-MS05;Initial Catalog=ParetoDev;Integrated Security=True"); dsQ2O dataQ2O=new dsQ2O(); private List<Category> items=new List<Category> (); public frmOrderRequest()
{
InitializeComponent();
// ShowSplashScreen(); removed for now to get to what needs to be worked ongetData();
}
private void ShowSplashScreen(){
splashParetoOE splash = new splashParetoOE(this); DialogResult result = splash.ShowDialog(this); switch (result){
//this will not return auto due to the fact the form is doing nothing case DialogResult.Abort:m_ExitOnLoad =
true; break; case DialogResult.No: string text = "Problem"; string caption = "Problem"; MessageBox.Show(this, text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);m_ExitOnLoad =
true; break; default: return;}
}
private void getData(){
dataQ2O.EnforceConstraints =
false; //ugly code to fill each table as we go, should be replaced later with better code //will need to redo using backgroundworker...KISS for now though SqlCommand cmdQ2O=new SqlCommand("Select * from Q2O", connParetodb); SqlDataAdapter daQ2O=new SqlDataAdapter(cmdQ2O);daQ2O.Fill(dataQ2O,
"Q2O"); SqlCommand cmdOrderPriority = new SqlCommand("Select * from OrderPriorityList", connParetodb); SqlDataAdapter daOrderPriority = new SqlDataAdapter(cmdOrderPriority);daQ2O.Fill(dataQ2O,
"OrderPriorityList");}
private void frmOrderRequest_Load(object sender, EventArgs e){
//Tree needs to be in order by Status (Open, In Progrees, Completed), Priority (Urgent, Stock, Other), Enter By, Request //Need to rework Category to reflect above statement also need to figure out relationshop or getParentRow foreach (DataRow orderRow in dataQ2O.Tables["Q2O"].Rows){
items.Add(
new Category((int)orderRow[0], (int)orderRow[1], (string)orderRow[5])); foreach (DataRow priorityRow in orderRow.GetParentRow("FK_Q2O_OrderPriorityList"));}
buildsmarttree();
}
private void buildsmarttree(){
//this code should eventually be move to ctlQ2OTree control //should also look at using collections rather then list..also create objects from data rather then dataset Node rootsNode = new Node("Order Request");rootsNode.Name =
"rootsNode";rootsNode.Text =
"Order Request";rootsNode.Tag =
"Root";rootsNode.Font =
new Font(smartTreeView1.Font.FontFamily, 12, FontStyle.Bold); this.smartTreeView1.Items.Add(rootsNode);RefreshTree(
null);}
internal void RefreshTree(object p_ObjectToSelect){
smartTreeView1.SuspendUpdate();
RefreshRootNode((
Node)smartTreeView1.Items[0]);smartTreeView1.ResumeUpdate();
}
private void RefreshRootNode(Node p_RootNode){
p_RootNode.Items.Clear();
foreach (Category catss in items){
Node priorityNode = new Node(catss.NodeText); // RefreshDateNode(dateNode);p_RootNode.Items.Add(priorityNode);
}
}
private void RefreshDateNode(Node p_dateNode){
}
}
}
I receive the follolwing error:
Error 1 foreach statement cannot operate on variables of type 'System.Data.DataRow' because 'System.Data.DataRow' does not contain a public definition for 'GetEnumerator' C:\Users\walter.weber\Documents\Visual Studio 2008\Projects\Pareto-OE\Pareto-OE\frmOrderRequest.cs 81 17 Pareto-OE
All fo the examples I can find including on Microsoft's site show the code for the getParentRow done like this. Any suggestions would be appreciated.
Replies
Know the answer? Post it — somebody with the same question will find it here.