class Program
{
static void Main(string[] args)
{
DataAccessObject obj=new Company();
obj.Run();
Console.Read();
}
}
public abstract class DataAccessObject
{
protected string connectionString;
protected DataSet dataSet;
public virtual void Connect()
{
connectionString=@"server=192.168.9.99/sqlserver2005;uid=sa;pwd=sasasa;database=aa;";
}
public abstract void Select();
public abstract void Display();
public virtual void Disconnecction()
{
connectionString="";
}
public void Run()
{
Connect();
Select();
Display();
Disconnecction();
}
}
public class Company:DataAccessObject
{
public override void Select()
{
string sql="select * from company";
SqlDataAdapter dataAdapter=new SqlDataAdapter(sql,connectionString);
dataSet=new DataSet();
dataAdapter.Fill(dataSet, "company");
}
public override void Display()
{
DataTable table=dataSet.Tables[0];
foreach(DataRow row in table.Rows)
{
Console.WriteLine(row["comp_name"].ToString());
}
}
}