How would I find a row with a column value? Say Im looking for people with the name "Lance" then once ive found Lance display the row of info for lance. Ive tried using select but cant seem to get it to work. Here is my code.
using System;
using System.Collections;
using System.Data;
namespace Table
{
class Program
{
static void Main(string[] args)
{
DataTable table = new DataTable("records");
DataColumn Col;
DataRow Row;
Col = new DataColumn();
Col.DataType = System.Type.GetType("System.Int32");
Col.ColumnName = "ID";
table.Columns.Add(Col);
Col = new DataColumn();
Col.DataType = System.Type.GetType("System.String");
Col.ColumnName = "FIRST";
table.Columns.Add(Col);
Col = new DataColumn();
Col.DataType = System.Type.GetType("System.Int32");
Col.ColumnName = "AGE";
table.Columns.Add(Col);
DataColumn[] PrimKey = new DataColumn[1];
PrimKey[0] = table.Columns["ID"];
table.PrimaryKey = PrimKey;
Row = table.NewRow();
Row["ID"] = 1;
Row["FIRST"] = "Steve";
Row["AGE"] = 34;
table.Rows.Add(Row);
Row = table.NewRow();
Row["ID"] = 2;
Row["FIRST"] = "Peter";
Row["AGE"] = 54;
table.Rows.Add(Row);
Row = table.NewRow();
Row["ID"] = 3;
Row["FIRST"] = "Lance";
Row["AGE"] = 94;
table.Rows.Add(Row);
// Display the data
foreach (DataRow m in table.Rows)
{
Console.Write("{0} ", m["ID"]);
Console.Write("{0} ", m["FIRST"]);
Console.Write("{0} ", m["AGE"]);
Console.WriteLine();
}
}
}
}