บทที่ 1 การเขียนโปรแกรมแบบ OOP
ถาม: OOP คืออะไร
ตอบ: OOP ย่อจาก Object Oriented Programming การเขียนโปรแกรมแบบวัตถุวิธี เป็นรูปแบบ (Paradigm) หรือแนวคิดอย่างหนึ่ง อันมีจุดมุ่งหมายเพื่อการสร้างซอฟท์แวร์
ถาม: Object คืออะไร
ตอบ: Object คือสิ่งที่ถูกสร้างจากคลาส มีคุณสมบัติและการทำงาน ตามที่นิยามไว้ในคลาส แต่ object แต่ละตัวจะมีสถานะและข้อมูลเป็นของตัวเองโดยไม่ขึ้นกับคลาสหรือ object อื่นๆ
ถาม: type คืออะไร
ตอบ: type คือชนิดหรือลักษณะของข้อมูล หากเป็น type ที่ compiler รับรู้อยู่ในตัวเรียกว่า primitive type หรือ build-in type การนิยามคลาสและ struct เป็นการสร้าง type ขึ้นใหม่โดยผู้ใช้
ถาม: กล่องดำคืออะไร (black box)
ตอบ: คืออุปกรณ์ที่เราสามารถนำมาใช้ประโยชน์ได้ โดยไม่จำเป็นต้องรู้รายละเอียดการทำงานภายในของมัน
ถาม: Object based programming หรือ [...]
Private im As Image
Private imPath As String
Public WriteOnly Property ImageFormPath() As String
Set(ByVal value As String)
im = Image.FromFile(value)
End Set
End Property
Public WriteOnly Property Images() As Image
Set(ByVal value As Image)
im = value
End Set
End Property
Is using SQL 2000, you might get the following error:
Microsoft OLE DB Provider for SQL Server error ‘80004005′
Login failed for user ‘BanManProSQL’. Reason: Not associated with a trusted SQL Server connection.
/dbconnect.asp, line 19
This error occurs because by default SQL 2000 [...]
private void Page_Load(object sender, System.EventArgs e)
{
if ( ! IsPostBack )
{
SqlConnection con = new SqlConnection(
“Data Source=localhost;Initial Catalog=northwind;” +
“Integrated Security=false;User id=YourUser;Password=YourPassword” );
SqlCommand selectCmd = new SqlCommand(”Ten Most Expensive Products”, con );
selectCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter( selectCmd ) ;
DataSet results = new DataSet();
da.Fill ( results, “Products” );
DataGrid1.DataSource = results;
DataGrid1.DataMember = “Products”;
DataGrid1.DataBind();
}
}