You are on page 1of 4

Implementing Single & Multi-Inheritance

using System; class classA { public int a; public classA() { a = 0; } public classA(int x) { a = x; } public void DisplayA() { Console.WriteLine("Base class classA's value is : {0}", a); } } class classB : classA { public int b; public classB() { b = 0; } public classB(int x, int y) { a = x; b = y; } public void DisplayB() { Console.WriteLine("Derived class classB's value is : {0}", b); } } class classC : classB { int c; public classC() { c = 0; } public classC(int x, int y, int z) { a = x; b = y; c = z; } public void DisplayC() { Console.WriteLine("Derived class classC's value is : {0}", c); } } class InheritenceDemo { public static void Main() { classA a = new classA(10) ; a.DisplayA() ; Console.WriteLine ("\nSingle Inheritance:\n") ; classB b = new classB(10, 20) ; b.DisplayA(); b.DisplayB(); Console.WriteLine ("\nMultilevel Inheritance:\n") ; classC c = new classC(10, 20, 30) ; c.DisplayA() ; c.DisplayB() ; c.DisplayC() ; } }

OUTPUT:

Implementing Provider and Adapter objects using ADO.NET

using System; using System.Data; using System.Data.OleDb; using System.Xml.Serialization; public class MainClass { public static void Main() { string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb"; string strAccessSelect = "SELECT * FROM MyTable"; DataSet myDataSet = new DataSet(); OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect,myAccessConn); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand); myAccessConn.Open(); myDataAdapter.Fill(myDataSet,"MyTable"); } catch(Exception ex) { Console.WriteLine("Error: {0}\n", ex.Message); return; } finally { myAccessConn.Close(); } DataTableCollection dta = myDataSet.Tables; Console.WriteLine("\nDisplaying the data from table using Data Provider & Adapter\n"); foreach (DataTable dt in dta) { Console.WriteLine("Found data table : {0}", dt.TableName); } DataRowCollection dra = myDataSet.Tables["MyTable"].Rows; foreach (DataRow dr in dra) { Console.WriteLine ("Name = {0} \t Mark 01 = {1} \t Mark 02 = {2} \t Mark 03 = {3}", dr[0], dr[1], dr[2], dr[3]) ; } } }

OUTPUT

You might also like