>>foreach (DataRow oRow in MyData.Tables[0].Rows) >>{ >> >>} >>>>
>using System; >using System.Collections.Generic; >using System.Linq; >using System.Text; >using System.IO; >using System.Data; >using System.Data.Sql; >using System.Data.SqlClient; > >namespace ConsoleApplication1 >{ > class MySample > { > public delegate void MyRowHandler(DataRow r); > public event MyRowHandler MyEvent; > > static void Main(string[] args) > { > MySample s = new MySample(); > s.MyEvent += new MyRowHandler(MyHandler1); > s.MyEvent += new MyRowHandler(MyHandler2); > s.MyEvent += oRow => > Console.WriteLine("Lambda expression call to my event handler: {0}", > oRow.Field<string>("CompanyName")); > > DataSet MyData = new DataSet(); > SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;trusted_connection=yes;database=Northwind"); > SqlCommand cmd = new SqlCommand("select * from customers where country = 'USA'", cn); > cn.Open(); > SqlDataReader rdr = cmd.ExecuteReader(); > MyData.Tables.Add(); > MyData.Tables[0].Load(rdr); > cn.Close(); > > foreach (DataRow oRow in MyData.Tables[0].Rows) > { > if (s.MyEvent != null) > s.MyEvent(oRow); > } > > > } > > private static void MyHandler1(DataRow row) > { > Console.WriteLine("MyHandler1 called: {0}", row[0].ToString()); > } > private static void MyHandler2(DataRow row) > { > Console.WriteLine("MyHandler2 called: {0}", row[0].ToString()); > } > } >}Cetin