001.
Imports
System.Data
002.
Imports
System.Data.OleDb
003.
004.
Partial
Class
showtypeform
005.
Inherits
System.Web.UI.UserControl
006.
Dim
objConn
As
OleDbConnection
007.
Dim
objCmd
As
OleDbCommand
008.
Dim
strSQL
As
String
009.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
010.
Dim
strConnString
As
String
011.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& Server.MapPath(
"database/mydatabase.mdb"
) &
";"
012.
objConn =
New
OleDbConnection(strConnString)
013.
objConn.Open()
014.
015.
If
Not
Page.IsPostBack()
Then
016.
BindData()
017.
End
If
018.
End
Sub
019.
Sub
BindData()
020.
strSQL =
"SELECT * FROM customer"
021.
022.
Dim
dtReader
As
OleDbDataReader
023.
objCmd =
New
OleDbCommand(strSQL, objConn)
024.
dtReader = objCmd.ExecuteReader()
025.
026.
027.
myGridView.DataSource = dtReader
028.
myGridView.DataBind()
029.
030.
dtReader.Close()
031.
dtReader =
Nothing
032.
033.
End
Sub
034.
035.
Protected
Sub
Page_Unload(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Unload
036.
objConn.Close()
037.
objConn =
Nothing
038.
End
Sub
039.
040.
Protected
Sub
myGridView_RowCancelingEdit(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewCancelEditEventArgs)
Handles
myGridView.RowCancelingEdit
041.
myGridView.EditIndex = -1
042.
myGridView.ShowFooter =
True
043.
BindData()
044.
End
Sub
045.
046.
Protected
Sub
myGridView_RowCommand(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewCommandEventArgs)
Handles
myGridView.RowCommand
047.
If
e.CommandName =
"Add"
Then
048.
049.
Dim
txtCustomerID
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddCustomerID"
), TextBox)
050.
051.
Dim
txtName
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddName"
), TextBox)
052.
053.
Dim
txtEmail
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddEmail"
), TextBox)
054.
055.
Dim
txtCountryCode
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddCountryCode"
), TextBox)
056.
057.
Dim
txtBudget
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddBudget"
), TextBox)
058.
059.
Dim
txtUsed
As
TextBox =
CType
(myGridView.FooterRow.FindControl(
"txtAddUsed"
), TextBox)
060.
061.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
& _
062.
" VALUES ('"
& txtCustomerID.Text &
"','"
& txtName.Text &
"','"
& txtEmail.Text &
"' "
& _
063.
" ,'"
& txtCountryCode.Text &
"','"
& txtBudget.Text &
"','"
& txtUsed.Text &
"') "
064.
objCmd =
New
OleDbCommand(strSQL, objConn)
065.
objCmd.ExecuteNonQuery()
066.
067.
BindData()
068.
End
If
069.
End
Sub
070.
071.
072.
073.
Protected
Sub
myGridView_RowDeleting(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewDeleteEventArgs)
Handles
myGridView.RowDeleting
074.
strSQL =
"DELETE FROM customer WHERE CustomerID = '"
& myGridView.DataKeys.Item(e.RowIndex).Value &
"'"
075.
objCmd =
New
OleDbCommand(strSQL, objConn)
076.
objCmd.ExecuteNonQuery()
077.
078.
myGridView.EditIndex = -1
079.
BindData()
080.
End
Sub
081.
082.
Protected
Sub
myGridView_RowEditing(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewEditEventArgs)
Handles
myGridView.RowEditing
083.
myGridView.EditIndex = e.NewEditIndex
084.
myGridView.ShowFooter =
False
085.
BindData()
086.
End
Sub
087.
088.
089.
Protected
Sub
myGridView_RowUpdating(
ByVal
sender
As
Object
,
ByVal
e
As
GridViewUpdateEventArgs)
Handles
myGridView.RowUpdating
090.
091.
Dim
txtCustomerID
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditCustomerID"
), TextBox)
092.
093.
Dim
txtName
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditName"
), TextBox)
094.
095.
Dim
txtEmail
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditEmail"
), TextBox)
096.
097.
Dim
txtCountryCode
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditCountryCode"
), TextBox)
098.
099.
Dim
txtBudget
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditBudget"
), TextBox)
100.
101.
Dim
txtUsed
As
TextBox =
CType
(myGridView.Rows(e.RowIndex).FindControl(
"txtEditUsed"
), TextBox)
102.
103.
strSQL =
"UPDATE customer SET CustomerID = '"
& txtCustomerID.Text &
"' "
& _
104.
" ,Name = '"
& txtName.Text &
"' "
& _
105.
" ,Email = '"
& txtEmail.Text &
"' "
& _
106.
" ,CountryCode = '"
& txtCountryCode.Text &
"' "
& _
107.
" ,Budget = '"
& txtBudget.Text &
"' "
& _
108.
" ,Used = '"
& txtUsed.Text &
"' "
& _
109.
" WHERE CustomerID = '"
& myGridView.DataKeys.Item(e.RowIndex).Value &
"'"
110.
objCmd =
New
OleDbCommand(strSQL, objConn)
111.
objCmd.ExecuteNonQuery()
112.
113.
myGridView.EditIndex = -1
114.
myGridView.ShowFooter =
True
115.
BindData()
116.
End
Sub
117.
118.
119.
End
Class