❶ VB 怎麼不用控制項操作資料庫
比如裡面一張表test,有3個欄位a,b,c,內容如下:
序號 a b c
11 2 3
24 5 6
37 8 9
1.修改a=1的記錄b的值為10:db.Execute("update test set b=10 where a=1")
2.刪除回a=7的記錄:db.Execute("delete from test where a=7")
3.添加一答條新記錄(a=11,b=12,c=13):db.Execute("insert into test values(11,12,13)")
❷ 請教vb如何連接oracle資料庫
辦法
添加部件:Microsoft ado data control 6.0
在窗體上添加一個adodc控制項,然後設置adodc控制項的屬性,選「使內用連接字元串」項邊上的容「生成」然後選Oracle驅動,並設好其它條件(要連的庫、用戶、密碼等),生成的字元串拷出來,賦值給ADODB.connectionsting就可以了,然後就可以刪除adodc控制項了。
❸ vb鏁版嵁搴擄紙鍩虹鐭ヨ瘑錛
VB鏁版嵁搴撴槸VisualBasic錛圴B錛夎璦涓鐢ㄤ簬綆$悊鏁版嵁鐨勯噸瑕佺粍鎴愰儴鍒嗐傚畠鍏佽稿紑鍙戜漢鍛樺壋寤恆佽誨彇銆佹洿鏂板拰鍒犻櫎鏁版嵁搴撲腑鐨勬暟鎹錛屼粠鑰屼嬌搴旂敤紼嬪簭鑳藉熸洿濂藉湴澶勭悊鏁版嵁銆傛湰鏂囧皢浠嬬粛VB鏁版嵁搴撶殑鍩虹鐭ヨ瘑錛屽寘鎷濡備綍鍒涘緩鏁版嵁搴撱佸備綍榪炴帴鏁版嵁搴撱佸備綍鏌ヨ㈠拰鏇存柊鏁版嵁絳夈
涓銆佸壋寤烘暟鎹搴
鍒涘緩VB鏁版嵁搴撶殑絎涓姝ユ槸鍒涘緩鏁版嵁搴撴枃浠躲俈B鏁版嵁搴撴敮鎸佸氱嶆暟鎹搴撶被鍨嬶紝鍖呮嫭Access銆丼QLServer銆丱racle絳夈傚湪鏈鏂囦腑錛屾垜浠灝嗕互Access鏁版嵁搴撲負渚嬭繘琛岃茶В銆
1.鎵撳紑Access杞浠訛紝閫夋嫨鈥滄柊寤虹┖鐧芥暟鎹搴撯濄
2.杈撳叆鏁版嵁搴撶殑鍚嶇О鍜屼繚瀛樿礬寰勶紝鐒跺悗鐐瑰嚮鈥滃壋寤衡濄
3.鍦ㄢ滃壋寤衡濋〉闈涓錛屽彲浠ラ夋嫨鍒涘緩琛ㄦ牸銆佹煡璇銆佽〃鍗曠瓑瀵硅薄銆傚湪鏈鏂囦腑錛屾垜浠灝嗗壋寤轟竴涓綆鍗曠殑琛ㄦ牸銆
4.鐐瑰嚮鈥滆〃鏍艱捐♀濓紝鍦ㄨ〃鏍間腑娣誨姞瀛楁碉紝騫惰劇疆瀛楁電殑灞炴с備緥濡傦紝鍙浠ユ坊鍔犱竴涓鈥滃撳悕鈥濆瓧孌靛拰涓涓鈥滃勾榫勨濆瓧孌碉紝騫惰劇疆瀹冧滑鐨勬暟鎹綾誨瀷涓衡滄枃鏈鈥濆拰鈥滄暟瀛椻濄
5.淇濆瓨琛ㄦ牸錛岀劧鍚庡叧闂瑼ccess杞浠躲
浜屻佽繛鎺ユ暟鎹搴
榪炴帴VB鏁版嵁搴撻渶瑕佷嬌鐢ˋDO錛圓ctiveXDataObjects錛夊硅薄銆侫DO鏄疺B涓鐢ㄤ簬璁塊棶鏁版嵁鐨勬爣鍑嗗硅薄搴擄紝瀹冩彁渚涗簡涓縐嶉氱敤鐨勬柟寮忔潵榪炴帴鍜岃塊棶鍚勭嶇被鍨嬬殑鏁版嵁婧愩
1.鎵撳紑VB欏圭洰錛岄夋嫨鈥滈」鐩鈥濊彍鍗曚腑鐨勨滃紩鐢ㄢ濄
2.鍦ㄢ滃彲鐢ㄥ紩鐢ㄢ濆垪琛ㄤ腑鍕鵑夆淢icrosoftActiveXDataObjects2.xLibrary鈥濓紝鐒跺悗鐐瑰嚮鈥滅『瀹氣濄
3.鍦╒B浠g爜涓娣誨姞浠ヤ笅浠g爜錛
```
DimcnAsADODB.Connection
Setcn=NewADODB.Connection
cn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C: est.mdb"
cn.Open
```
鍏朵腑錛屸渃n鈥濇槸榪炴帴瀵硅薄錛屸淐onnectionString鈥濇槸榪炴帴瀛楃︿覆錛屽畠鎸囧畾浜嗘暟鎹搴撶被鍨嬪拰璺寰勩
4.榪炴帴鎴愬姛鍚庯紝鍙浠ヤ嬌鐢ㄤ互涓嬩唬鐮佹潵鍏抽棴榪炴帴錛
```
cn.Close
Setcn=Nothing
```
涓夈佹煡璇㈡暟鎹
鏌ヨVB鏁版嵁搴撻渶瑕佷嬌鐢ˋDO瀵硅薄涓鐨凴ecordset瀵硅薄銆俁ecordset瀵硅薄鏄疺B涓鐢ㄤ簬瀛樺偍鍜屾搷浣滄暟鎹鐨勫硅薄錛屽畠鍙浠ュ規暟鎹搴撹繘琛屾煡璇銆佹洿鏂般佹彃鍏ュ拰鍒犻櫎絳夋搷浣溿
1.鍦╒B浠g爜涓娣誨姞浠ヤ笅浠g爜錛
```
DimrsAsADODB.Recordset
Setrs=NewADODB.Recordset
rs.Open"SELECT*FROMtable1",cn
```
鍏朵腑錛屸渞s鈥濇槸Recordset瀵硅薄錛屸淥pen鈥濇柟娉曟寚瀹氫簡鏌ヨ㈣鍙ュ拰榪炴帴瀵硅薄銆
2.鏌ヨ㈢粨鏋滃彲浠ラ氳繃浠ヤ笅浠g爜榪涜岃誨彇錛
```
DoWhileNotrs.EOF
Debug.Printrs.Fields("name").Value
Debug.Printrs.Fields("age").Value
rs.MoveNext
Loop
```
鍏朵腑錛屸淓OF鈥濆睘鎬ц〃紺烘槸鍚﹀埌杈句簡鏌ヨ㈢粨鏋滈泦鐨勬湯灝撅紝鈥淔ields鈥濆睘鎬ц〃紺烘煡璇㈢粨鏋滈泦涓鐨勫瓧孌碉紝瀹冧滑鍙浠ラ氳繃鍚嶇О鎴栫儲寮曡繘琛岃塊棶錛屸淢oveNext鈥濇柟娉曠敤浜庣Щ鍔ㄥ埌涓嬩竴鏉¤板綍銆
鍥涖佹洿鏂版暟鎹
鏇存柊VB鏁版嵁搴撻渶瑕佷嬌鐢≧ecordset瀵硅薄涓鐨勨淯pdate鈥濇柟娉曘傝ユ柟娉曠敤浜庢洿鏂拌板綍闆嗕腑鐨勬暟鎹錛屽苟灝嗘洿鏀逛繚瀛樺埌鏁版嵁搴撲腑銆
1.鍦╒B浠g爜涓娣誨姞浠ヤ笅浠g爜錛
```
rs.Fields("age").Value=20
rs.Update
```
鍏朵腑錛屸淔ields鈥濆睘鎬ц〃紺鴻佹洿鏂扮殑瀛楁碉紝瀹冧滑鍙浠ラ氳繃鍚嶇О鎴栫儲寮曡繘琛岃塊棶錛屸淯pdate鈥濇柟娉曠敤浜庝繚瀛樻洿鏀廣
2.鏇存柊鎴愬姛鍚庯紝鍙浠ラ氳繃浠ヤ笅浠g爜榪涜岃誨彇錛
```
rs.MoveFirst
Debug.Printrs.Fields("age").Value
```
鍏朵腑錛屸淢oveFirst鈥濇柟娉曠敤浜庣Щ鍔ㄥ埌鏌ヨ㈢粨鏋滈泦鐨勭涓鏉¤板綍銆
浜斻佸皬緇
鏈鏂囦粙緇嶄簡VB鏁版嵁搴撶殑鍩虹鐭ヨ瘑錛屽寘鎷鍒涘緩鏁版嵁搴撱佽繛鎺ユ暟鎹搴撱佹煡璇㈡暟鎹鍜屾洿鏂版暟鎹絳夈傞氳繃瀛︿範鏈鏂囷紝璇昏呭彲浠ヤ簡瑙VB鏁版嵁搴撶殑鍩烘湰鎿嶄綔錛屽苟鑳藉熷湪瀹為檯寮鍙戜腑搴旂敤榪欎簺鐭ヨ瘑銆
❹ VB 連接Oracle
VB6.0可通過Adodc數據訪問控制項的屬性頁進行連接Oracle資料庫。
1)建立數據工程,在窗體添加Adodc數據訪問控制項。滑鼠選中Adodc控制項-右鍵-Adodc屬性-使用連接字元串-生成。
❺ 鍦╒B6.0涓濡備綍榪炴帴Oracle鏁版嵁搴撹〃錛岃鋒暀澶х墰浠浜
鑰侀棶棰樹簡錛岄殢渚誇笂緗戝氨鎵懼緱鍒幫紝
浠ヤ笅渚涘弬鑰,杞鑷猚cid銆
棣栧厛瑕佸畨瑁匫RACLE瀹㈡埛絝鎴栨湇鍔″櫒絝,寤哄ソDB浠ュ強SERVICE,榪炴帴鎴愬姛鍚庡氨鍙浠ュ紑濮嬩簡,浠ヤ笅鏄疺B璁塊棶ORACLE鐨勪唬鐮:
Option Explicit
'浠ヤ笅鏄涓浜涘彉閲忎互鍙婂弬鏁扮殑瀹氫箟
'DB鐨勫悕縐
Public Const strdbname = "DBNAME"
'鐢ㄦ埛鍚
Public Const strusr = "BLUESKY35"
'瀵嗙爜
Public Const strpwd = "PASSWORD"
'OraSession
Public OraSession As Object
'OraDatabase
Public OraDB As OraDatabase
'OraDynaset
Public OraDyn As OraDynaset
'榪炴帴ORACLE鐨勫嚱鏁
'榪炴帴鎴愬姛:true 榪炴帴澶辮觸:false
Public Function f_connect() As Boolean
On Error GoTo ierr
f_connect = False
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDB = OraSession.OpenDatabase(strdbname, strusr & "/" & strpwd, 0&)
f_connect = True
Exit Function
ierr:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
f_connect = False
End Function
'閫氳繃浼犲叆SQL璇鍙ヤ粠鏁版嵁搴撶殑琛ㄩ噷鍙栧緱璁板綍
Public Function f_select(strsql As String) As OraDynaset
On Error GoTo ierr
Set OraDyn = OraDB.CreateDynaset(strsql, ORADYN_READONLY)
Set f_select = OraDyn
Exit Function
ierr:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
Set f_select = Nothing
End Function
'鎵ц屾洿鏂拌鍙,榪斿洖鍙楁湰嬈℃洿鏂板獎鍝嶇殑璁板綍鏁
Public Function f_execute(strsql As String) As Boolean
On Error GoTo ierr
f_execute = False
OraDB.BeginTrans
f_execute = OraDB.ExecuteSQL(strsql)
Exit Function
ierr:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
OraDB.Rollback
End Function
'鏂寮榪炴帴
'鏂寮鎴愬姛:true 鏂寮澶辮觸:false
Public Function f_disconnect() As Boolean
On Error GoTo ierr
f_disconnect = False
If Not OraDyn Is Nothing Then
OraDyn.Close
End If
Set OraSession = Nothing
OraDB.Close
Set OraDB = Nothing
f_disconnect = True
Exit Function
ierr:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
f_disconnect = False
End Function
灝嗕互涓婁唬鐮佹斁鍏ユā鍧,鐩存帴璋冪敤鍗沖彲.