?? masters3.vb
字號:
Option Strict Off
Imports System
Imports System.Collections
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class BaseClass
Inherits System.Web.UI.Page
protected Grid1 as DataGrid
Protected Message as label
Protected acode_category as dropdownlist
Protected AddPanel as Panel
Dim myConnection As OleDbConnection
Dim myCommand As OleDbDataAdapter
Dim ds As New DataSet
Dim ConnStr As String
Dim SQL As String
Sub Page_Load(Source As Object, E As EventArgs)
ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=ASPNET;User ID=sa;"
myConnection = New OleDbConnection(ConnStr)
if NOT (isPostBack)
rebind
end if
End Sub
Sub ReBind()
SQL = "select m.*, g.code_display as category "
SQL = SQL + "from masters m, groups g "
SQL = SQL + " where m.code_category = g.code_value"
myCommand = New OleDbDataAdapter(SQL, myConnection)
myCommand.Fill(ds, "masters")
'Binding a Grid
Grid1.DataSource=ds.Tables("masters").DefaultView
Grid1.DataBind()
SQL = "Select * from groups order by code_display"
myCommand = New OleDbDataAdapter(SQL, myConnection)
myCommand.Fill(ds, "groups")
'populate drop down list
acode_category.DataSource=ds.Tables("groups").DefaultView
acode_category.DataBind()
hidePanel()
End Sub
Sub Grid1_Edit(Sender As Object, E As DataGridCommandEventArgs)
Grid1.EditItemIndex = E.Item.ItemIndex
ReBind()
End Sub
Sub Grid1_Cancel(Sender As Object, E As DataGridCommandEventArgs)
Grid1.EditItemIndex = -1
ReBind()
End Sub
sub hidePanel()
if AddPanel.visible = true then
AddPanel.visible = false
end if
end sub
Sub RunSql(sql as string)
try
Dim mycommand2 As New OleDbCommand(sql,myConnection)
myConnection.Open()
myCommand2.ExecuteNonQuery()
myConnection.Close()
'turn off editing
Grid1.EditItemIndex = -1
Catch ex As OleDbException
' SQL error
Dim errItem As OleDbError
Dim errString As String
For Each errItem In ex.Errors
errString += ex.Message + "<br/>"
Next
Message.Text = "SQL Error.Details follow:<br/><br/>" & errString
Message.Style("color") = "red"
catch myException as Exception
Response.Write("Exception: " + myException.ToString())
Message.Style("color") = "red"
end try
rebind
response.write(sql)
End sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -