Reading specific column values in each datarow
Hi,
using C#;
using VS2005;
I have a dataset that contains several datatables. What I wish to do is search each row in one of the tables and read/copy the value of a column into a variable. I will then manipulate the variable as needed. Specifically, the dataTable is "MembershipDetails" and the column is "MembershipNumber". The dataset is called "myclubDataSet".
The purpose of all this is to determine the next sequential membership number.
If someone could be so good enough to write the code for me I would very much appreciate it because I can't find a simple straightforward example anywhere on the net to learn from.
I know how to do a sql command to do this but I don't want to do it on the database. I wish to achieve it using the dataset.
Thanks in advance.

mateen ashraf16 reputationPosted Aug 2, 2006, 10:31 AM EDT
CAN YOU TRY THIS CODE..? // MyCSharp\DataTables\DataRowView.cs // Author: Mesbah U. Ahmed using System; using System.Data; public class DataRowView1 { public static void displayData(DataTable dt, DataRowVersion drv) { Console.WriteLine(drv.Format() + " Version"); foreach (DataRow r in dt.Rows) { Console.Write(r[0, drv] + ", "); Console.Write(r[1,drv]); Console.WriteLine(); } Console.WriteLine(); } public static void Main() { // Instantiate a DataTable object. DataTable myDTable = new DataTable("Products"); // Get a DataColumn and a DataRow reference DataColumn myDCol; DataRow myDRow; // create and add the first column myDCol = new DataColumn(); myDCol.DataType = System.Type.GetType("System.String"); myDCol.ColumnName = "PCode"; myDCol.DefaultValue = "Some Default"; myDTable.Columns.Add(myDCol); // Create and add the second column myDCol= new DataColumn(); myDCol.DataType = System.Type.GetType("System.Decimal"); myDCol.ColumnName = "Price"; myDCol.DefaultValue = 9999999.99; myDTable.Columns.Add(myDCol); // Now instantiate two DataRow objects and add them to Rows collection myDRow = myDTable.NewRow(); // Do not specify the PCode. Let it be the default myDRow["Price"] = 20.35; myDTable.Rows.Add(myDRow); myDRow = myDTable.NewRow(); myDRow["PCode"] = "P200"; // Let the Price assume the default myDTable.Rows.Add(myDRow); Console.WriteLine(); // Stage 1 Console.WriteLine("=== Stage 1. Initially: After Add(Row) But Before Accept Changes ==="); displayData(myDTable,DataRowVersion.Default); displayData(myDTable, DataRowVersion.Current); // displayData(myDTable,DataRowVersion.Original); // Does not exist // displayData(myDTable,DataRowVersion.Proposed); // Does not exist // Stage 2 myDTable.AcceptChanges(); Console.WriteLine("=== Stage 2. After AcceptChanges ===="); displayData(myDTable,DataRowVersion.Default); // exists displayData(myDTable,DataRowVersion.Original); // exists displayData(myDTable, DataRowVersion.Current); // exists // displayData(myDTable,DataRowVersion.Proposed); // does not exist // Stage 3. Change some values in the data table myDTable.Rows[0].BeginEdit(); // Edit first row myDTable.Rows[0]["PCode"] = "P100"; myDTable.Rows[1].BeginEdit(); // Edit the second row myDTable.Rows[1]["Price"] = 299.78; // Now both rows are in Edit mode and both data are proposed Console.WriteLine("===Stage 3. After we Edited the rows, but before AcceptChange ==="); displayData(myDTable,DataRowVersion.Default); displayData(myDTable,DataRowVersion.Original); displayData(myDTable, DataRowVersion.Current); displayData(myDTable,DataRowVersion.Proposed); // Stage 4: End the Edit sessions for both rows // Note: The EndEdit commits the changes. The AcceptChanges() also // commits the changes but it also adds new rows and deletes marked rows for (int i=0; iGlen Harvy102 reputationPosted Aug 2, 2006, 5:31 PM EDT