⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 masters3.vb

📁 聊天 聊天 聊天 聊天 聊天 聊天
💻 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 + -