Hi,
The following line populates a datagrid using a strongly typed dataset.
dsEmps is the .xsd file
in the foreach line I would like to loop through each record
I get an error on the foreach line and it says:
specified cast is not valid
I think this line has to be somehow casted
employeeDetailsData.Employees.Rows
EmpBusRule.EmpService.dsEmps employeeDetailsData;
EmpBusRule.Employees br =
employeeDetailsData = br.GetDataEmployee();
if (employeeDetailsData.Employees.Rows.Count < 1)
{
throw new Exception("No record found.");
}
grdEmps.DataSource = employeeDetailsData.Employees; foreach(EmpData.dsEmps.EmployeesRow row in employeeDetailsData.Employees.Rows)
{
string x = row.FirstName;
}
Thanks

strongly typed dataset
Nicolas B.
Hi!
Ok I figured that out...
To be able to use foreach loop properly it should be able to extract each item from collection and cast it to the type variable provided in the loop which is not happening in your case. So I thought EmployeeRow will be availble in BLL which is not the case thats why you don't see it and loop can't cast it.
I don't know the exact composition of your application, but i from your posts what I'm able to figured out is following:
DAL contains typed dataset which contains class for Employee table and it has also class for EmployeeRow.
BLL I'm not sure but I guess you are writing some wrapper for Employee in DAL and then using it in presentation. Since BLL doesn't have EmployeeRow class therefore its not available for casting in foreach loop.
Would like to shed some light, otherwise it'll take moretime with guess work.
cheers
abbarron
there are two ways:
row[index], where index is the ordinal number starting from zero or string name for that column.
row["ColumnName"]
cheers
emanon
using the code sample that you have now, how do I refer to the column number (i.e. ordinal) please
Thanks
Joshd23
Hello again,
This was simply a problem of intellisense.
the foreach loop works fine now.
Thank y ou
Praveenk_RS
I fo not get
.EmployeesRow
in the foreach loop
Any ideas please
Thanks
richard wolfe
Hi!
As you can see EmpData.dsEmps.EmployeesRow is clearly different from employeeDetailsData.Employees.Rows as they belong to different projects. It'll work if you change loop to follwoing:
foreach(EmpBusRule.EmpService.dsEmps.EmployeesRow row in employeeDetailsData.Employees.Rows)
cheers.
bat313
Column name should be selecte from the Strongly Typed Dataset
Thanks
cb1024
you can try this I'm not sure whether it'll work or not.
DataColumn
dc = (DataColumn)row["ColumnName"];dc.Ordinal
I hope this helps
cheers
Shivakumara V
The following line is accessable to the whole form:
private EmpBusRule.EmpService.dsEmps employeeDetailsData;
now I would like to refer to a column of the employees table as follows:
employeeDetailsData.Employees.FirstName.Ordinal
Thanks
Waiman Li
John Askew
dsEmployeesList.Tables["EmployeesList"].Columns["EmployeeID"].Ordinal;
What is the equivalent for Strong Type dataset usingthe previous sample codes
is it something like:
EmpBusRule.EmpService.dsEmps.firstName.ordinal
Thanks
RGIMatt
instead of using this line
defaultView.RowFilter = dsEmployeesList.Tables["EmployeesList"].Columns["FirstName"].ColumnName + " = 'Nancy'";
I would like to use this line:
defaultView.RowFilter = employeeDetailsData.Employees.FirstName.ColumnName + " = 'Nancy'";
Thanks
Whatonly
Andy Hooper
Hi!
I didn't get you..
I'm online for sometime and my email is swat_jam@hotmail.com
add me I'll discuss with you I'll be glad if I wud be of any help.
cheers