001.
Imports
System.Data
002.
Imports
System.Data.SqlClient
003.
Public
Class
_Default
004.
Inherits
System.Web.UI.Page
005.
006.
#Region " Web Form Designer Generated Code "
007.
008.
009.
<System.Diagnostics.DebuggerStepThrough()>
Private
Sub
InitializeComponent()
010.
011.
End
Sub
012.
Protected
WithEvents
lblHeaderCustomerID
As
System.Web.UI.WebControls.Label
013.
Protected
WithEvents
lblCustomerID
As
System.Web.UI.WebControls.Label
014.
Protected
WithEvents
lblHeaderName
As
System.Web.UI.WebControls.Label
015.
Protected
WithEvents
lblName
As
System.Web.UI.WebControls.Label
016.
Protected
WithEvents
lblHeaderEmail
As
System.Web.UI.WebControls.Label
017.
Protected
WithEvents
lblEmail
As
System.Web.UI.WebControls.Label
018.
Protected
WithEvents
lblHeaderCountryCode
As
System.Web.UI.WebControls.Label
019.
Protected
WithEvents
lblCountryCode
As
System.Web.UI.WebControls.Label
020.
Protected
WithEvents
lblHeaderBudget
As
System.Web.UI.WebControls.Label
021.
Protected
WithEvents
lblBudget
As
System.Web.UI.WebControls.Label
022.
Protected
WithEvents
lblHeaderUsed
As
System.Web.UI.WebControls.Label
023.
Protected
WithEvents
lblUsed
As
System.Web.UI.WebControls.Label
024.
Protected
WithEvents
lblText
As
System.Web.UI.WebControls.Label
025.
Protected
WithEvents
myData1
As
System.Web.UI.WebControls.DataGrid
026.
Protected
WithEvents
myDataGrid2
As
System.Web.UI.WebControls.DataGrid
027.
Protected
WithEvents
myDataGrid1
As
System.Web.UI.WebControls.DataGrid
028.
Protected
WithEvents
myDataGrid3
As
System.Web.UI.WebControls.DataGrid
029.
030.
031.
032.
Private
designerPlaceholderDeclaration
As
System.
Object
033.
034.
Private
Sub
Page_Init(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Init
035.
036.
037.
InitializeComponent()
038.
End
Sub
039.
040.
#End Region
041.
042.
Dim
clsDB
As
New
clsDatabase
043.
Private
Sub
Page_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
044.
045.
Call
myDataReader()
046.
Call
myDataSet()
047.
Call
myDataTable()
048.
Call
myQueryExecuteScalar()
049.
Call
myExecuteNonQuery()
050.
Call
myExecuteTransaction()
051.
End
Sub
052.
053.
054.
Sub
myDataReader()
055.
Dim
strSQL
As
String
056.
Dim
dtReader
As
SqlDataReader
057.
strSQL =
"SELECT * FROM customer "
058.
dtReader = clsDB.QueryDataReader(strSQL)
059.
Me
.myDataGrid1.DataSource = dtReader
060.
Me
.myDataGrid1.DataBind()
061.
062.
063.
064.
065.
066.
067.
068.
069.
070.
071.
clsDB.Close()
072.
End
Sub
073.
074.
075.
Sub
myDataSet()
076.
Dim
strSQL
As
String
077.
Dim
ds
As
DataSet
078.
strSQL =
"SELECT * FROM customer "
079.
ds = clsDB.QueryDataSet(strSQL)
080.
Me
.myDataGrid2.DataSource = ds.Tables(0).DefaultView
081.
Me
.myDataGrid2.DataBind()
082.
083.
084.
085.
086.
087.
088.
089.
090.
091.
092.
clsDB.Close()
093.
End
Sub
094.
095.
096.
Sub
myDataTable()
097.
Dim
strSQL
As
String
098.
Dim
dt
As
DataTable
099.
strSQL =
"SELECT * FROM customer "
100.
dt = clsDB.QueryDataTable(strSQL)
101.
Me
.myDataGrid3.DataSource = dt
102.
Me
.myDataGrid3.DataBind()
103.
104.
105.
If
dt.Rows.Count > 0
Then
106.
Me
.lblCustomerID.Text = dt.Rows(0)(
"CustomerID"
)
107.
Me
.lblName.Text = dt.Rows(0)(
"Name"
)
108.
Me
.lblEmail.Text = dt.Rows(0)(
"Email"
)
109.
Me
.lblCountryCode.Text = dt.Rows(0)(
"CountryCode"
)
110.
Me
.lblBudget.Text = dt.Rows(0)(
"Budget"
)
111.
Me
.lblUsed.Text = dt.Rows(0)(
"Used"
)
112.
End
If
113.
clsDB.Close()
114.
End
Sub
115.
116.
117.
Sub
myQueryExecuteScalar()
118.
Dim
strSQL
As
String
119.
strSQL =
"SELECT MAX(Budget) FROM customer "
120.
Me
.lblText.Text = clsDB.QueryExecuteScalar(strSQL)
121.
clsDB.Close()
122.
End
Sub
123.
124.
125.
Sub
myExecuteNonQuery()
126.
Dim
strSQL1, strSQL2, strSQL3
As
String
127.
128.
129.
strSQL1 =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
& _
130.
" VALUES('C005','Weerachai Nukitram','webmaster@thaicreate.com','TH','200000','100000')"
131.
If
clsDB.QueryExecuteNonQuery(strSQL1) =
True
Then
132.
133.
Else
134.
135.
End
If
136.
clsDB.Close()
137.
138.
139.
strSQL2 =
"UPDATE customer SET Budget = '3000000' WHERE CustomerID = 'C005' "
140.
If
clsDB.QueryExecuteNonQuery(strSQL2) =
True
Then
141.
142.
Else
143.
144.
End
If
145.
clsDB.Close()
146.
147.
148.
strSQL3 =
"DELETE FROM customer WHERE CustomerID = 'C005' "
149.
If
clsDB.QueryExecuteNonQuery(strSQL3) =
True
Then
150.
151.
Else
152.
153.
End
If
154.
clsDB.Close()
155.
End
Sub
156.
157.
158.
Sub
myExecuteTransaction()
159.
Dim
strSQL1, strSQL2, strSQL3
As
String
160.
161.
162.
clsDB.TransStart()
163.
164.
Try
165.
166.
strSQL1 =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
& _
167.
" VALUES('C005','Weerachai Nukitram','webmaster@thaicreate.com','TH','200000','100000')"
168.
clsDB.TransExecute(strSQL1)
169.
170.
171.
strSQL2 =
"UPDATE customer SET Budget = '3000000' WHERE CustomerID = 'C005' "
172.
clsDB.TransExecute(strSQL2)
173.
174.
175.
strSQL3 =
"DELETE FROM customer WHERE CustomerID = 'C005' "
176.
clsDB.TransExecute(strSQL3)
177.
178.
179.
clsDB.TransCommit()
180.
181.
Catch
ex
As
Exception
182.
183.
clsDB.TransRollBack()
184.
End
Try
185.
clsDB.Close()
186.
End
Sub
187.
188.
End
Class