Create MS SQL Database on Visual Studio

On the tab Server Explorer choose "Create New SQL Server Database".



Because we are using Database sql that was bundled with visual studio 2008, then we fill the server name with "sqlexpress", "dot" indicating we are looking the local machine.



Choose your authentication, whether "Windows Authentication" or "SQL Server Authentication".
Type your database name, we are here name it as "Apprentice_DB", and click "OK" button

  1. On tab Server Explorer choose "Apprentice_DB" and right click choose "Add New Table".
  2. Specify your Database table by fill in the "column_name","Data Type" and "Allow Nulls".
  3. After finish, click disk icon and you will be prompted  the table name.


Teacher_ID in this table plays as the primary key, to make this field auto increment, click properties on this field and specify the identity specification and choose "Is Identity" to "Yes", so when you add new record this field would generate new numeric record consider to amount of the current record.



Create other table and name it "Apprentice_Table", just like previous table, make your parameter table or properties something like this





And the final step we are going to make relationship between the two tables that already being made !



Make the relationship like the picture above !

NB: Teacher_ID on Teacher_Table should have the column types as type as Teacher_Code on the Apprentice_Table.

After the relationship already being created, we could fill the record to the both of tables. You should fill the Teacher_Table at  first because this table plays as master table that will being referred by Apprentice_Table.

After you finish on filling the record to the table, just press this button (Execute SQL), with pressing this button  you would make change to database server



The Database that already being created was located at "C:\Program Files\MicrosoftSQL Server\MSSQL.1\Data" at this directory you would find "Apprentice_DB.mdf" and "Apprentice_DB_Log.LDF" both of files should exist in order to make the database work correctly.

Bookmark and Share

ADO.Net Architecture


Ado .NET Architecture


DESCRIPTION:
DataSource : DataSource was the initial name for Oracle Database, Microsoft SQL Server, XML file, etc.

Connection: Connection class can be set as "Open" or "Close", with notes "Open" was used for operation that directly access to Datasource.

Object Oriented Programming (Introduction)

Inheritance

On OOP(Object Oriented Programming), all class, even the class that build java API and .net Library, were subclasses from it's superclass object. Contoh hirarki dari kelas dapat dilihat pada diagram dibawah ini.
Class on the top level, or class that inherit was called "superclass", even though the class that receive inheritance was called "subclass".

OOP Hierarchy
Inheritance has big advantage on Object Oriented Programming because  the behavior and method on the superclass can automatically inherited to it's subclasses, so this method can be used on the subclass that receive inheritance from it's superclass. 


Nb : Method = Procedure Or Function




1.2 Define SuperClass and SubClass

To get the class, we use the keyword "extends"  for java and ":" for C#. With illustration like this following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Console_Test
{
class Vehicle
{
protected string Engine = "One Cilinder" ,VehicleName ="My Private Car",Type=VehicleType.SUV.GetHashCode().ToString();
protected bool FourWheelDrive = true;



public enum VehicleType
{


CityCar=0,SUV=1,Truck=2,SportCar=4
}


public Vehicle()
{
// System.Console.Out.Write("This was Vehicle Constructor");

}

public string GetName()
{
return this.VehicleName;
}


public void SetName(string UrVehicleName)
{
this.VehicleName = UrVehicleName;
}


public void SetEngineType(string UrEngineType)
{
this.Engine = UrEngineType;
}


public string GetEngineType()
{
return Engine;
}


public string GetType()
{
return Type;
}


public void SetType(string Type_)
{
Type = Type_;
}


public bool GetForWheelDrive()
{
return this.FourWheelDrive;
}


public void SetForWheelDrive(bool WD)
{
this.FourWheelDrive = WD;
}


}
}



Then we define the subclass of  Vehicle class with name "AudiTT"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Console_Test
{
class AudiTTCar : Vehicle
{

public AudiTTCar()
{
this.SetName("AudiTT");
this.SetForWheelDrive(true);
this.SetEngineType("4 Cilinder");
this.SetType(Vehicle.VehicleType.SUV.GetHashCode().ToString());
}

}
}
On the "Main method"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Console_Test
{
class Program
{
static void Main(string[] args)
{
System.Console.Out.WriteLine("Nama Kendaraan Ini Adalah :{0}",new Vehicle().GetName());

System.Console.Out.WriteLine("Jenis Mesin :{0}", new Vehicle().GetForWheelDrive() ? "4WD" : "Bukan 4WD");

System.Console.Out.WriteLine("Silinder Mesin :{0}", new Vehicle().GetEngineType());

System.Console.Out.WriteLine("Jenis Mobil :{0}", Enum.GetName(typeof(Vehicle.VehicleType),int.Parse(new Vehicle().GetType())));

System.Console.Out.WriteLine("================================");

System.Console.Out.WriteLine("Nama Kendaraan Ini Adalah :{0}", new AudiTTCar().GetName());

System.Console.Out.WriteLine("Jenis Mesin :{0}", new AudiTTCar().GetForWheelDrive() ? "4WD" : "Bukan 4WD");

System.Console.Out.WriteLine("Silinder Mesin :{0}", new AudiTTCar().GetEngineType());

System.Console.Out.WriteLine("Jenis Mobil :{0}", Enum.GetName(typeof(AudiTTCar.VehicleType), int.Parse(new AudiTTCar().GetType())));

System.Console.ReadKey();
}
}
}

Bookmark and Share

Extension Method On C#

Extension methods allow existing classes to be extended without relying on inheritance or having to change the class's source code. This means that if you want to add some methods into the existing class you can do it quite easily. Here's a couple of rules to consider when deciding on whether or not to use extension methods:

  1. Extension methods cannot be used to override existing methods
  2. An extension method with the same name and signature as an instance method will not be called
  3. The concept of extension methods cannot be applied to fields, properties or events
  4. Use extension methods sparingly....overuse can be a bad thing!