Ⅰ VB闂棰 锛氭柊寤哄伐绋嬩腑鐨勯棶棰
淇濆瓨灞炴х殑鍙樺寲銆 娉ㄦ剰Property DataServerName鏂规硶鐨勭敤娉曪紝姝ゆ柟娉曚笌ReadProperties 鍜學riteProperties浜嬩欢鍦ㄤ竴璧蜂娇鐢ㄣ 姝ゆ椂闇瑕佷娇鐢ㄧ敤鎴锋帶浠剁殑InitProperties浜嬩欢鎸囧畾姝ゅ睘鎬х殑鍒濆嬪硷細 Private Sub UserControl_InitProperties() m_DataServerName = m_def_DataServerName End Sub 鍗充娇鐢ㄦ埛娌℃湁璁剧疆鍒濆嬪硷紝杩欎簺浠g爜涔熶細纭淇濊剧疆浜嗕竴涓鍒濆嬪笺 鑷充簬DataBaseName銆丄dministratorName銆丳asseordName 灞炴х殑鍒涘缓杩囩▼璺烡ataServername灞炴х殑鍒涘缓杩囩▼瀹屽叏涓鏍凤紝杩欓噷灏变笉鍐嶉噸澶嶅彊杩般 鈼嗕娇鐢≒ropertyBag瀵硅薄 鐢ㄦ埛杩橀渶瑕佷负WriteProperties鍜孯eadProperties浜嬩欢鍒涘缓浠g爜,浠庤屼繚鎶DataServername銆丏ataBaseName銆丄dministratorName銆丳asseordName灞炴у湪璁捐¢樁娈电殑灞炴у笺傝繖涓や釜浜嬩欢閮戒娇鐢≒ropertyBag 瀵硅薄淇濆瓨鍜屾绱DataServername銆丏ataBaseName銆丄dministratorName銆丳asseordName灞炴х殑鍊笺侾ropertyBag瀵硅薄鑳藉熶繚鎸丏ataServername銆丏ataBaseName銆 AdministratorName銆丳asseordName鐨勮捐″笺傚叿浣撳疄鐜颁唬鐮佸備笅锛 Private Sub UserControl_ReadProperties(PropBag As PropertyBag) m_DataServerName = PropBag.ReadProperty("DataServerName", m_def_DataServerName) m_DataBaseName = PropBag.ReadProperty("DataBaseName", m_def_DataBaseName) m_AdministratorName = PropBag.ReadProperty("AdministratorName", m_def_AdministratorName) m_PasswordName = PropBag.ReadProperty("PasswordName", m_def_PasswordName) End Sub Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("DataServerName", m_DataServerName, m_def_DataServerName) Call PropBag.WriteProperty("DataBaseName", m_DataBaseName, m_def_DataBaseName) Call PropBag.WriteProperty("AdministratorName", m_AdministratorName, m_def_AdministratorName) Call PropBag.WriteProperty("PasswordName", m_PasswordName, m_def_PasswordName) End Sub 鐢变簬杩欎袱涓杩囩▼鏄閽堝"瀹瑰櫒"瀵硅薄鐨勶紝鍥犳ゆ墍鏈夊睘鎬у肩殑淇濆瓨鍜岃诲彇閮介氳繃杩欎袱涓杩囩▼鏉ュ疄鐜帮紝鑰屼笉鏄姣忎釜灞炴ч兘闇瑕佸崟鐙鐨勪袱涓杩囩▼銆傚叾涓锛孭ropertyBag灏辨槸"瀹瑰櫒瀵硅薄"鐨勫悕绉般 WriteProperty鏂规硶鏈変笁涓鍙傛暟锛氱涓涓瀛楃︿覆鏍囪瘑闇瑕佷繚瀛樼殑灞炴э紝绗浜屼釜鍙傛暟鏄闇瑕佷繚瀛樼殑鍊硷紝鏈鍚庣殑鍙傛暟鏄灞炴х殑缂虹渷鍊笺 ReadProperty 鏂规硶闇瑕佷袱涓鍙傛暟锛氫竴涓瀛楃︿覆鐢ㄦ潵淇濆瓨灞炴х殑鍚嶇О锛屽彟涓涓涓虹己鐪佸笺 鍦ㄧ獥浣撲笂缁樺埗ActiveX鎺т欢鐨勯偅涓鍒伙紝灏变細寮濮嬫墽琛孉ctiveX鎺т欢鐨勪唬鐮併傚湪鎺т欢璁捐¤繃绋嬩腑锛屽皢DataServername銆丏ataBaseName銆丄dministratorName銆丳asseordName灞炴х殑榛樿ゅ艰剧疆涓猴細 Const m_def_DataServerName = "lyc" Const m_def_DataBaseName = "pubs" Const m_def_AdministratorName = "sa" Const m_def_PasswordName = "" 褰撶劧锛屼篃鍙浠ュ湪绋嬪簭杩愯屾椂澶氭′慨鏀瑰畠銆傛帶浠剁殑姝e父琛屼负鏄褰撶▼搴忕粓姝㈡椂鎭㈠嶅叾榛樿ゅ硷紝杩欐牱澧炲姞浜嗕繚鎸佸睘鎬х殑涓ょ嶇嫭绔嬬姸鎬佺殑瑕佹眰銆 绠瑷涔嬶紝濡傛灉鍦ㄨ捐¢樁娈垫敼鍙樹簡涓涓灞炴у硷紝閭d箞鎺т欢蹇呴』寰楀埌杩欎釜鏂板硷紝鑰屼笉鏄浣跨敤榛樿ゅ笺傜浉鍙嶏紝濡傛灉鍦ㄧ▼搴忚繍琛屾椂鏀瑰彉灞炴у硷紝閭d箞褰撹繑鍥炶捐$姸鎬佹椂锛屾帶浠跺繀椤绘绱㈡ゅ睘鎬у笺 PropertyBag瀵硅薄鍏佽窤ctiveX鎺т欢瀛樿串鏈夊叧瀹冭嚜宸辩殑灞炴у硷紝浣垮畠鑳芥墽琛岃繖涓鍔ㄤ綔銆侾ropertyChanged 鏂规硶浼氶氱煡鐢ㄦ埛宸茬粡鏀瑰彉浜嗕竴涓灞炴с傞氳繃浜嗚В绋嬪簭鐨勭姸鎬佷互鍙婃槸鍚﹁皟鐢ㄤ簡PropertyChanged鏂规硶锛孷B 灏卞彲浠ユ縺鍙慦riteProperties鍜孯eadProperties浜嬩欢銆 鈼嗕负ShowDataBase鏂规硶缂栧啓浠g爜 ShowDataBase鏂规硶瀹炵幇鍦↙istView鎺т欢涓鏄剧ずSelect鍛戒护鎵鎵ц岀殑鏁版嵁搴撴搷浣滅粨鏋溿傚湪鍏跺叿浣撳疄鐜拌繃绋嬩腑閲囩敤浜 ADO锛圓ctiveX Data Objects锛夌殑鏁版嵁瀛樺彇鏂规硶銆侫DO鐨勪富瑕佺壒鐐规槸浣跨敤鏇村姞瀹规槗锛岃块棶閫熷害鏇村揩,鑰屽圭佺洏鍜屽瓨鍌ㄥ归噺鐨勮佹眰鏇村皬,ADO鏀鎸佸缓绔嬪悇绉嶅㈡埛/鏈嶅姟鍣ㄦā寮忎笌鍩轰簬Web鐨勫簲鐢ㄧ▼搴忥紝鍏锋湁杩滅▼鏁版嵁鏈嶅姟RDS锛圧emote Data Service锛夌殑鐗规э紝閫氳繃RDS鑳藉熷湪涓娆″線杩斾腑灏嗘湇鍔″櫒绔鐨勬暟鎹浼犻佸埌瀹㈡埛绔鐨勫簲鐢ㄧ▼搴忔垨Web椤甸潰涓锛屽苟鍦ㄥ㈡埛绔瀵规暟鎹杩涜屽勭悊鍚庯紝绔嬪嵆鏇存柊鏈嶅姟鍣ㄧ鐨勬暟鎹銆傞噰鐢ˋDO鎵鍩轰簬鐨凮LE DB鎶鏈锛屽彲浠ュ圭數瀛愰偖浠躲佹枃鏈鏂囦欢銆佹暟鎹琛ㄦ牸绛夊悇绫绘暟鎹閫氳繃缁熶竴鐨勬帴鍙API鎺ュ彛杩涜屽瓨鍙栵紝鏄杩滅▼鏁版嵁瀛樺彇鐨勪竴涓涓昏佸彂灞曟柟鍚戙係howDataBase鏂规硶鍏锋湁涓涓瀛楃︿覆鍙傛暟锛屼絾鏃犱换浣曡繑鍥炲硷紝鍏蜂綋浠g爜濡備笅鎵绀猴細 Public Sub showdatabase(ssql As String) Dim AdoDatabase As New ADODB.Connection Dim AdoTable As New ADODB.Recordset Dim scnn As String Dim response As String Dim I As Integer On Error GoTo errorhandle scnn = "Provider=SQLOLEDB;Data Source=" & Trim(m_DataServerName) & "; Initial Catalog=" & Trim(m_DataBaseName) & "; User Id=" & Trim(m_AdministratorName) & "; Password=" & Trim(m_PasswordName) & ";" AdoDatabase.Open scnn AdoTable.CursorType = adOpenKeyset AdoTable.LockType = adLockOptimistic AdoTable.CursorLocation = adUseClient AdoTable.Open ssql, AdoDatabase, , , adCmdText If AdoTable.BOF And AdoTable.EOF Then response = MsgBox("娌℃湁绗﹀悎鏉′欢鐨勮板綍锛侊紒", vbOKOnly + vbInformation, "鏁版嵁搴撴帶浠") AdoTable.Close Set Adotable=Nothing AdoDatabase.Close Set AdoDataBase=Nothing Exit Sub End If ListView1.ColumnHeaders.Clear ListView1.ListItems.Clear Dim clmX As ColumnHeader For I = 0 To AdoTable.Fields.Count - 1 Set clmX = ListView1.ColumnHeaders.Add() With clmX .Text = AdoTable.Fields(I).Name End With Next Dim itmX As ListItem AdoTable.MoveFirst Do While Not AdoTable.EOF Set itmX = ListView1.ListItems.Add() With itmX If IsNull(AdoTable.Fields(0).Value) Then .Text = "NULL" Else .Text = AdoTable.Fields(0).Value End If End With For I = 1 To AdoTable.Fields.Count - 1 If IsNull(AdoTable.Fields(I).Value) Then itmX.SubItems(I) = "NULL" Else itmX.SubItems(I) = AdoTable.Fields(I).Value End If Next AdoTable.MoveNext Loop ListView1.View = lvwReport AdoTable.Close Set Adotable=Nothing AdoDatabase.Close Set AdoDataBase=Nothing Exit Sub errorhandle: RaiseEvent Errordatabase End Sub 褰撳规暟鎹搴撶殑鎿嶄綔鍙戠敓閿欒鍚庯紝闄や簡涓嶈兘姝e父鏄剧ず浠ュ栵紝杩樺簲閫氱煡瀹夸富绋嬪簭鐢ㄦ埛銆傚彲浠ラ氳繃鍒涘缓涓涓鍙鍋欵rrordatabase鐨勪簨浠跺疄鐜颁笂杩板姛鑳姐傝佸垱寤鸿繖涓浜嬩欢锛屾妸涓嬭堪浠g爜娣诲姞鍒癠serControl瀵硅薄鐨凣eneralDeclarations娈典腑銆 Public Event Errordatabase() 姝や簨浠剁殑宸ヤ綔鍍忓叾浠栨帶浠剁殑浜嬩欢涓鏍枫備娇鐢ㄦ帶浠剁殑鐢ㄦ埛鍙浠ュ皢浠g爜鏀惧埌杩欎釜浜嬩欢涓锛岀敤鎴疯佸仛鐨勫敮涓鐨勪簨鎯呭氨鏄鐢≧aiseEvent鏂规硶婵鍙戞や簨浠躲 锛7锛夌紪璇戞帶浠堕儴浠讹紙.ocx 鏂囦欢锛夈 鐜板湪宸茬粡瀹屾垚浜咲ataListView鎺т欢鐨勫垱寤哄伐浣滐紝涓轰簡鍦―ataLV宸ョ▼澶栦篃鍙浠ヤ娇鐢ㄨユ帶浠讹紝鍙闇灏咲ataLV宸ョ▼缂栬瘧.ocx鎺т欢閮ㄤ欢鍗冲彲銆 鍦ㄣ愬伐绋嬬粍銆戠獥鍙e崟鍑汇怐ataLV銆戜互閫夋嫨璇ュ伐绋嬶紝鍦ㄣ愭枃浠躲戣彍鍗曚笂鍗曞嚮銆愮敓鎴怐ataLV.ocx銆戯紝鍦ㄣ愮敓鎴愬伐绋嬨戝硅瘽妗嗕腑閫夋嫨鎺т欢瀛樻斁鐨勭洰褰曞悗锛 鍗曞嚮銆愮‘瀹氥戝嵆鍙鍒涘缓.ocx 鏂囦欢銆 涓鏃︾敓鎴愪簡.ocx鏂囦欢鐨勬帶浠讹紝灏卞彲浠ヨ薄浣跨敤鍏跺畠鎺т欢涓鏍锋潵闅忓績鎵娆插湴浣跨敤瀹冧簡銆 4锛夌粨鏉熻 ActiveX鎶鏈鍙浠ョ伒娲汇侀珮鏁堢殑瀹炵幇鍙浜や簰銆侀噸鍏ャ侀噸鐢ㄣ佸畬鍏ㄥ垎甯冨紡銆佷笌璇瑷鏃犲叧鐨勫悇绉嶅簲鐢ㄣ傞殢鐫ActiveX鎶鏈鐨勫彂灞曪紝ActiveX鎺т欢鍦ㄥ簲鐢ㄧ▼搴忎腑鐨勪綔鐢ㄥ皢浼氭樉寰楄秺鏉ヨ秺 閲嶈侊紝閭d箞鍒涘缓涓涓鍔熻兘瀹屽杽銆佸叿鏈夎嚜宸辩壒鑹茬殑ActiveX鎺т欢灏遍潪甯稿叿鏈夌幇瀹炴剰涔夈傚彧瑕佹帉鎻′簡鍒涘缓ActiveX鎺т欢鐨勫熀鏈鏂规硶锛屽氨涓嶉毦鍒涘缓鑷瀹氬埗鐨勫彲鍦ㄥ悇绉嶅簲鐢ㄩ嗗煙浣跨敤鐨凙ctiveX鎺т欢銆 浣嗘槸锛孉ctiveX鎶鏈涔熸湁涓浜涙槑鏄剧己鐐癸紝ActiveX鎶鏈渚濊禆浜嶹indows骞冲彴锛屽瑰箍娉涘簲鐢ㄧ殑UNIX骞冲彴鐩鍓嶄粛涓嶅吋瀹癸紝鍙﹀ ActiveX鍦ㄨ稿氭柟闈㈢殑鎬ц兘杩樿緝寮憋紝ActiveX鎶鏈浠嶉渶瑕佷笉鏂瀹屽杽鍜屽彂灞