Hi,
Using Strongly Typed dataset, I would like to refer to a column.
This is what I am doing at present:
//dsEmps is the .xsd
EmpBusRule.EmpService.dsEmps employeeDetailsData;
int intEmployeeIDColumn = employeeDetailsData.Employees.Columns[0].Ordinal;
int intFirstNameOrdinal = employeeDetailsData.Employees.Columns[2].Ordinal;
My intention is to use something like :
int intEmployeeIDColumn = employeeDetailsData.Employees.EmployeeID.Ordinal;
int intEmployeeIDColumn = employeeDetailsData.Employees.FirstName.Ordinal;
If I do this the the compiler error is:
'EmpBusRule.EmpService.dsEmps.EmployeesDataTable' does not contain a definition for 'FirstName'
Thanks

.xsd ordinal
Gonzo11
Hima S
The whole purpose of .xsd is not to type in the fiel names.
Do you know how to do this please
cambler
if I use the following code then I can get to the column 'firstname', so I guess this proves that my .xsd is correct
foreach
(EmpBusRule.EmpService.dsEmps.EmployeesRow row in employeeDetailsData.Employees.Rows){
string x = row.FirstName.ToString();}
The problem is that I do not want to use the loop to get to the columns.
for eacmple: I would like to assign the column position to an integer as follows,but would like to use the columnname rather than this:
int
intFirstNameOrdinal = employeeDetailsData.Employees.Columns[2].Ordinal;Any thoughts please
Thanks
gena fayez saad
Actually, the point of strongly typed datasets is that you can use strongly typed, named properties. There are two problems here:
1. The compiler error is telling you exactly what's wrong: your Employees table doesnt have a FirstName property. You need to fix the XSD that is generating that table to include that column.
2. Once you fix that, FirstName will be a property that returns a string. It will not have an Ordinal property; that's the whole point of using strongly typed fields, so that you can refer to them directly by their name, not by their column position. I think you need to take another look at your design and see why you need the ordinal in the first place. If you decide that you really do need the position, you need to follow Mintu's suggestion.
SenthilD
Hi,
Ok, I am not getting what you guys are say, because it does not seem that the .xsd file is incorrect. I checked it and the FirstName column is indeed present.
Don't you think that the fact that I can get to the FirstName column in the foreach loop means that there is nothing wrong with the .xsd file
Thanks
dpghost
Hi!
That's good fmardani that you've started another thread for this topic and I please mark the "strongly typed dataset"
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=234677&SiteID=1
thread as solved by clicking the anwer button so that other looking for same problem could benefit from it.
To my knowledge there are two ways to access column of table in a database. One by ordinal and other by its name, correct me if I'm wrong. By looking on your problem I found that you don't want to use these two ways.
int intFirstNameOrdinal = employeeDetailsData.Employees.Columns[2].Ordinal;
In the above code you want to get the ordinal but by specifying the column name. There two ways of doing it, (1) you specify the column name your self and extract its ordinal (2)use loop for columns which you don't want to use.
Now I want you to help us to help you by anwer following question:
1) How do you want to do this . Can you write psuedocode for that.
2) How and where you are using Ordinal value that you extract.
Answer to these may lead to some solution but not gaurenteed.
cheers
Brian Berg
use employeeDetailsData.Table["Employees"].Columns["EmployeeID"].Ordinal instead of employeeDetailsData.Employees.EmployeeID.Ordinal
Ordinal property of DataColumn will let u know the pos. in DataColumn Collection.
use
employeeDetailsData.Tables["Employees"].Columns["FirstName"].Ordinal instead of employeeDetailsData.Employees.FirstName.Ordinal;
Andrey Makarov
Ok, let's say I would like to refer to a column i.e. as below so that I can get the value of the firstname column
string strEmployeeFirstNameColumn = employeeDetailsData.Employees.FirstName
Is this correct
Thanks