VB °æ (¾«»ªÇø)
open: Permission denied
·¢ÐÅÈË: zxfsnow (±ðÅÂÎÒÉËÐÄ), ÐÅÇø: VB
±ê Ìâ: VB5.0ÖÐÔ¶³ÌÊý¾Ý¿âµÄ·ÃÎÊ
·¢ÐÅÕ¾: ¹þ¹¤´ó×϶¡Ïã (2000Äê06ÔÂ01ÈÕ19:12:32 ÐÇÆÚËÄ), תÐÅ
·¢ÐÅÈË: hy ( ÔƼ䱤Ö÷), ÐÅÇø: VB
±ê Ìâ: VB5.0ÖÐÔ¶³ÌÊý¾Ý¿âµÄ·ÃÎÊ
·¢ÐÅÕ¾: Òûˮ˼Դվ (Sat Jul 17 21:13:03 1999) , Õ¾ÄÚÐżþ
ÔÚVB5.0ÖУ¬ÓÃMicrosoft JetÊý¾Ý¿âÒýÇæºÍÊý¾Ý·ÃÎʶÔÏóDAO£¨Data Access Object£©¿É
ÒÔ´´ ½¨¹¦ÄÜÇ¿´óµÄ¿Í»§/·þÎñÆ÷Ó¦ÓóÌÐò¡£¶ÔÔ¶³ÌÊý¾Ý¿âµÄ·ÃÎÊÊÇ¿ª·¢ÕâÀàÓ¦ÓóÌÐòµÄ
¹Ø¼ü»·½Ú£¬±¾ÎĽ«½éÉÜÔÚVB5.0ÖÐÓÃDAOͨ¹ýMiscrosoft JetÊý¾Ý¿âÒýÇæ·ÃÎÊÔ¶³ÌÊý¾Ý¿â
µÄ·½·¨¡£
ÓÃDAO·ÃÎÊÔ¶³ÌÊý¾Ý¿â´óÌåÉÏ¿ÉÒÔͨ¹ýÈý²½À´ÊµÏÖ£¬¼´Êý¾ÝÁ¬½Ó¡¢Êý¾Ý´¦ÀíºÍ¶Ï¿ªÁ¬½Ó¡£
ÏÂÃà Ö÷Òª½éÉÜÊý¾ÝÁ¬½ÓºÍÊý¾Ý´¦ÀíµÄ¾ßÌå²Ù×÷¡£
¡¡
Ò»¡¢Êý¾ÝÁ¬½Ó
DAOÒ»°ãͨ¹ýÁ´½ÓÔ¶³Ì±íµÄ·½Ê½À´½øÐÐÊý¾ÝÁ¬½Ó¡£ÕâÑù£¬Êý¾ÝËäȻפÁôÔÚÔ¶³ÌÊý¾ÝÔ´ÉÏ£¬
µ«ÔÔ ±¾µØµÄMicrosoftJetÊý¾Ý¿âÖпÉÒÔ´æ´¢ÓëÔ¶³ÌÊý¾ÝµÄÓÀ¾ÃÐÔÁ¬½Ó£¬Í¬Ê±»º´æÁ´½ÓµÄ
±í½á¹¹ÐÅÏ¢£¬´Ó¶øÔÚÏÂÒ»´Î·ÃÎʸñíʱ£¬²»ÓÃÔٴδӷþÎñÆ÷ÖмìË÷ÕâЩ½á¹¹ÐÅÏ¢£¬¼Ó¿ì
ÁËÁ¬½ÓËٶȡ£Ò»µ©Á´½ÓÁËÒ»¸
±í£¬¸ÃÁ´½Ó±ã»á±£ÁôÔÚ¸÷»á»°Æڼ䣬ֱµ½Á¬½Ó¶Ï¿ª¡£Á´½Ó
Ô¶³Ì±íµÄ¾ßÌå²Ù×÷ÊÇ£º
ÓÃOpenDatabase·½·¨´ò¿ª½«Òª°üº¬¸ÃÁ´½ÓµÄ±¾µØMicrosoft JetÊý¾Ý¿â
ÓÃCreateTableDef·½·¨ÔÚ¸ÃÊý¾Ý¿âÖд´½¨Ò»¸öеÄTableDef¶ÔÏó
½«TableDef¶ÔÏóµÄConnectÊôÐÔÉèÖÃΪһ¸öºÏ·¨µÄÁ¬½Ó×Ö·û´®£¬±êʶҪ·ÃÎʵÄÔ¶³ÌÊý¾Ý¿â
ÀàÐ
¡¢Êý¾ÝÎļþµÄ·¾¶ÒÔ¼°Óû§ÃûºÍÔ¶³ÌÊý¾ÝÔ´ÃÜÂëµÈ¡£
½«TableDef¶ÔÏóµÄSourceTableNameÊôÐÔÉèÖÃΪԶ³ÌÊý¾Ý¿âÖÐÒª·ÃÎʵıíµÄÃû³Æ¡£
Ìí¼ÓTableDef¶ÔÏóµ½TableDefs¼¯ºÏÖС£
ʵÏÖÁ´½ÓÔ¶³Ì±í²Ù×÷µÄ¹ý³ÌÈçÏ£º
Public Sub LinkTable(strDB As String, strRoDB As String, strCn As String, st
rTdf
As String, _linkTdfName As String)
Dim linkTdf As New TableDef
Set dbs = OpenDatabase(strDB)
linkTdf.Name = linkTdfName
100
tempTable = UCase(linkTdf.Name)
For i = 0 To dbs.TableDefs.Count - 1
If UCase(dbs.TableDefs(i).Name) = tempTable Then
If MsgBox(linkTdfName + " ÒÑ ´æ ÔÚ£¬ ÊÇ ·ñ ɾ ³ý £¿", _
vbQuestion + vbYesNo) = vbYes Then
dbs.TableDefs.Delete linkTdf.Name
Exit For
Else: MsgBox " ÖØ Ð Êä Èë Р±í Ãû"
linkTdfName = InputBox(" Р±í Ãû")
GoTo 100
End If
End If
Next i
Set linkTdf = dbs.CreateTableDef(linkTdfName) ' Á´ ½Ó Ô¶ ³Ì ±í
linkTdf.Connect = ";database=" + strCn
linkTdf.SourceTableName = strTdf
dbs.TableDefs.Append linkTdf
End Sub
ÉÏÊö¹ý³ÌÓÃÀ´ÊµÏÖÔ¶³Ì±íµÄÁ¬½Ó£¬ËüÓÐ5¸ö²ÎÊý£¬ÆäÖÐstrRoDBÊÇÒª·ÃÎʵÄÔ¶³ÌÊý¾Ý¿âÃû
£¨°ü
·¾¶£©£»strTdfÊǸÃÊý¾Ý¿âÖеıíÃû£»strDBÊÇÒªÁ´½ÓµÄ±¾µØÊý¾Ý¿â£¨°üÀ¨Â·¾¶£©£»li
nkTd
NameÊDZ¾µØÊý¾Ý¿âµÄÒ»¸öбíÃû£¬ÓÃÀ´½¨Á¢Ô¶³Ì±íµÄÁ´½Ó£»strCnÊÇÖ¸¶¨Á¬½ÓÐÅÏ¢µÄ×Ö·û
´®¡
ÐèÒªÌرð×¢Ò
µÄÊÇ£¬³ýÁËÔÚ·ÃÎÊÔ¶³ÌMicrosoft JetÊý¾Ý¿âʱ£¬Á¬½Ó×Ö·û´®ÒªÒÔ·Ö
ºÅ£¨£»£©¿ªÍ·Í⣬ָ¶¨
½ÓÐÅÏ¢µÄ×Ö·û´®¶¼±ØÐëÒÔËù·ÃÎʵÄÔ ³ÌÊý¾Ý¿âÀàÐÍ¿ªÍ·¡£DAO¿ÉÒÔ·ÃÎʵÄÔ¶³ÌÊý¾ÝÔ´ÓÐ
ÒÔÏÂ
Àࣺ
.Microsoft JetÊý¾ÝÔ´£¬È磺AccessÊý¾Ý¡£
.IISAM£¨¿É°²×°µÄË÷Òý»¯Ë³Ðò·ÃÎÊ·½·¨£©¸ñʽÊý¾ÝÔ´£¬È磺FoxPro¡¢Paradox¡¢dBASEÊý
¾Ý¡£
.ODBCÊý¾ÝÔ´£¬È磺SQLServerÊý¾Ý¡¢OracleÊý¾Ý¡£
ÀýÈ磺ÉèÍøÂç·þÎñÆ÷ÃûΪserver£¬¹²ÏíĿ¼ΪC:\SalesµÄFoxPro3.0Êý¾Ý¿â£¬Á¬½Ó×Ö·û´®
Ó¦Î
strCn="FoxPro3.0;database=\\server\c$\Sales\Region1"
´ËÍ⣬DAOͨ¹ýMicrosoft JetÊý¾Ý¿âÒýÇæ·ÃÎÊÔ¶³ÌÊý¾Ýʱ£¬»¹¿ÉÒÔÓÃOpenDatabase·½·¨
Ö±½Ó
¿ªÔ¶³Ì±í¡£ÔÚ±¾µØÊý¾Ý¿âÖв¢Î´´æ´¢ÓëÔ¶³ÌÊý¾ÝÔ´½¨Á¢Á¬½ÓËùÐèÒªµÄÐÅÏ¢¡£Èç¹ûʹÓÃÁ´
½Ó·
ʽ·ÃÎÊÊý¾Ý£¬Ôò²»±ØÔÚÿ´Î»á»°¿ªÊ¼Ê±ÌṩÁ¬½ÓÐÅÏ¢£¬´Ó¶ø¿ÉÒÔÌá¸ßЧÂÊ¡£
¡¡
¶þ¡¢Êý¾Ý´¦Àí
Êý¾ÝÁ¬½Ó½¨Á¢ºó£¬¿ÉÒÔÓÃOpenRecordset·½·¨´ò¿ªÒ»¸ö¼Ç¼¼¯£¬²¢¿ÉÓÃDBGrid¿Ø¼þºÍDat
a¿Ø¼
·½±ãµØä¯ÀÀÕû¸ö¼Ç¼¼¯¡£Èç¹ûʹÓñíÀàÐÍ£¨Table-type£©¼Ç¼¶ÔÏó£¬Ôò¶ÔÓ¦µÄÊÇÒ»
¸öʵ¼Ê´æ
µÄÊý¾Ý¿â±í£¬ÔÚ¶àÓû§»·¾³Ï£¬ÆäËüÓû§¶ Êý¾ÝµÄÐ޸ĻáÁ¢¼´·´Ó³µ ±íÖУ»Èç¹ûʹÓö¯
̬¼
ÀàÐÍ£¨Dynas
et-type£©¼Ç¼¶ÔÏó£¬Ôò¶ÔÓ¦µÄ¼È¿ÉÒÔÊÇÒ»¸ö±íÖÐÈ«²¿¼Ç¼£¬ÓÖ¿ÉÒÔÊÇÒ»¸ö²éѯµÄ½á¹û£¬
²¢Ç
¿ÉÒÔ¸üмǼ¼¯ÖеļǼ£»Èç¹ûʹÓÿìÕÕÀàÐÍ£¨Snapshot-type£©¼Ç¼¶ÔÏó£¬Ôò¶ÔÓ¦
µÄ¿ÉÒÔÊ
±íÖеÄÈ«²¿¼Ç¼£¬Ò²¿ÉÒÔÊÇÒ»¸ö²éѯ½á¹û£¬µ«²»ÄܽøÐмǼµÄÔö¼Ó¡¢É¾³ýºÍÐÞ
¸Ä²Ù×÷¡£´ËÍâ
»¹¿ÉÒÔ½¨Á¢
ÆäËüÀàÐ͵ļǼ¶ÔÏó£¬Èç½öÏòÇ°ÐÍ£¨Forward Only-type£©¼Ç¼¶ÔÏóºÍ¶¯Ì¬ÐÍ£¨Dynamic
-typ
£©¼Ç¼¶ÔÏó¡£
ÏÂÃæÊÇ´ò¿ª¶¯Ì¬¼¯¼Ç¼¶ÔÏó²¢ÏÔʾ¼Ç¼µÄ¹ý³Ì£º
Public Sub rst_display(strDB As String, strRst As String, strForm As Form)
Set dbs = OpenDatabase(strDB)
Set rst = dbs.OpenRecordset(strRst, dbOpenDynaset)
strForm!Data1.DatabaseName = dbs.Name
strForm!Data1.RecordSource = rst.Name
¡¡
strForm!Data1.Refresh
strForm!DBGrid1.ReBind
End Sub
ÉÏÊö¹ý³ÌÓÐÈý¸ö²ÎÊý£¬ÆäÖÐstrDBÓÃÀ´Ö¸¶¨±¾µØÊý¾Ý¿âÃû£¨°üÀ¨Â·¾¶£©£¬linkTdfNameÊÇ
ÔÚ±¾
Êý¾Ý¿âÖÐн¨µÄÁ´½ÓÔ¶³Ì±íµÄ±íÃû£¬strFormÊÇÍø¸ñ¿Ø¼þºÍÊý¾Ý¿Ø¼þËùÔڵĴ°ÌåÃû¡£µ÷
ÓôË
³Ì¿ÉÒÔ»ùÓÚÐÂ±í½¨Á¢Ò»¸ö¶¯Ì¬¼¯ÀàÐ͵ļǼ¶ÔÏ󣬲¢¿ÉÔÚÍø¸ñÖÐä¯ÀÀ¸÷¸ö¼Ç¼¡£
¶Ï¿ªÁ¬½Ó¿ÉÒÔͨ¹ý¹Ø±ÕÓ¦ÓóÌÐò»òÉèÖÃÁ¬½Ó³¬Ê±À´ÊµÏÖ¡£×¢Ò⣺Èç¹û¶ÔÊý¾Ý¿â¶ÔÏóʹÓÃ
Clos
·½·¨£¬ÔòÓÉÓÚÔÚMiscrosoft JetÊý¾Ý¿âÒýÇæÄÚ²¿»º´æÁËÁ¬½Ó£¬Êµ¼ÊÉÏÁ¬½Ó²¢Î´È¡Ïû¡£
¡¡
Èý¡¢Ó¦ÓþÙÀý
ÒÔÉϽéÉÜÁËÓÃDAO·ÃÎÊÔ¶³ÌÊý¾Ý¿âµÄ¾ßÌå²Ù×÷£¬ÏÂÃæͨ¹ýÒ»¸öÀý×Ó˵Ã÷Á´½ÓÔ¶³Ì±íºÍ½¨Á¢
¼ÇÂ
¼¯¶ÔÏóµÄ·½·¨¡£
Ê×ÏȽ¨Á¢Ò»¸öй¤³Ì£¬ÔÚ´°ÌåÉÏ»5¸öÃüÁî°´Å¥£¬1¸öÊý¾Ý¿Ø¼þºÍ1¸öÊý¾ÝÍø¸ñ¿Ø¼þ£¨DBG
rid£
¡£¸÷¶ÔÏóµÄÊôÐÔÉèÖüû±í1¡£
±í1 ´°Ìå1¶ÔÏóÊôÐÔÉèÖÃ
¶Ô Ïó ±ê Ì⣨Caption£© Ãû ³Æ£¨Name£©
´°Ìå Ô¶³ÌÊý¾Ý·ÃÎÊ Form1
ÃüÁî°´Å¥1 Á´½ÓÔ¶³Ì±í cmd Á´½Ó
ÃüÁî°´Å¥2 Ìí¼Ó cmdAdd
ÃüÁî°´Å¥3 ɾ³ý cmdDel
ÃüÁî°´Å¥4 ÐÞ¸Ä cmdModify
ÃüÁî°´Å¥5 ½áÊø cmdEnd
Êý¾Ý¿Ø¼þ Data1 Data1
Êý¾ÝÍø¸ñ DBGrid1
ÆäÖÐDBGrid1ÖеÄDataSourceÊôÐÔÉèΪData1£¬ÃüÁî°´Å¥2£¬3£¬4µÄVisibleÊôÐÔÉèΪFals
e¡£
±àдÈçÏÂʼþ¹ý³Ì£º
Private Sub cmdAdd_Click() ' Ìí ¼Ó ¼Ç ¼ ×Ó ¹ý ³Ì
On Error GoTo errHandler
With rst
.AddNew
For i = 0 To .Fields.Count - 1 ' ±é Àú ¼Ç ¼ ¼¯ ÖÐ µÄ ÿ ¸ö ×Ö ¶Î
' ÔÚ Êä Èë ¿ò ÖÐ Êä Èë ¸÷ ×Ö ¶Î µÄ Êý ¾Ý
.Fields(i).Value = InputBox
(" Êä Èë ¼Ç Â¼ ЊϢ" & vbCr + " ×Ö ¶Î Ãû£º" + .Fields(i).Name)
Next i
.Update
End With
Data1.Refresh
DBGrid1.ReBind
errHandler: ' ´í Îó ´¦ Àí
Select Case Err
Case 3022, 3421
MsgBox (Error + vbCr + " Êä Èë ÎÞ Ð§")
Exit Sub
Case Else
Response = 0
Exit Sub
End Select
End Sub
¡¡
Private Sub cmdDel_Click() ' ɾ ³ý ¼Ç ¼ ¹ý ³Ì
On Error GoTo errHandler
BeginTrans ' ÊÂ Îñ ´¦ Àí
With Data1.Recordset
If .BOF And .EOF Then Exit Sub
' Èç ¹û û ÓÐ ¼Ç ¼£¬ ÍË ³ö ¹ý ³Ì
.Delete ' ɾ ³ý
If .BOF And .EOF Then
' Èç ¹û û ÓÐ ¼Ç ¼£¬ ÍË ³ö ¹ý ³Ì
Exit Sub
ElseIf .EOF Then .MoveLast
' Èç ¹û ɾ ³ý µÄ ÊÇ ×î ºó Ò» Ìõ ¼Ç ¼£¬ ¹â ±ê ÒÆ ÖÁ ×î ºó Ò» ¼Ç ¼
Else: .MoveNext
' ÒÆ ÖÁ Ï һ Ìõ ¼Ç ¼
End If
End With
If MsgBox(" È· ʵ Òª ɾ ³ý Õâ Ò» ¼Ç ¼ £¿",
vbQuestion + vbYesNo) = vbYes Then
CommitTrans ' È· ÈÏ
Data1.Refresh
Else
Rollback ' ³· Ïû ¸Ä ¶¯
Data1.Refresh
End If
errHandler: ' ´í Îó ´¦ Àí
Select Case Err
Case 3021 ' ÎÞ µ± Ç° ¼Ç ¼
MsgBox (" ÎÞ µ± Ç° ¼Ç ¼£¬ Çë Ñ¡ Ôñ Òª ɾ ³ý µÄ ¼Ç ¼")
Exit Sub
Case Else
MsgBox (Error)
Exit Sub
End Select
End Sub
Private Sub cmdEnd_Click()
End ' ½á Êø Ó¦ Óà ³Ì Ðò
End Sub
Private Sub cmdModify_Click()
DBGrid1.AllowUpdate = True ' ÔÊ Ðí ÐÞ ¸Ä
End Sub
Privatev Sub cmd Á´ ½Ó_Click()
Form1.Hide
Form2.Show
End Sub
Private Sub DBGrid1_AfterColUpdate(ByVal ColIndex As Integer)
' Êý ¾Ý ÐÞ ¸Ä ºó ´¥ ·¢ ¸Ã Ê ¼þ
On Error GoTo err1
Data1.Refresh
err1:
Select Case Err
Case 0
Response = 0
Case Else
Exit Sub
End Select
End Sub
Private Sub DBGrid1_BeforeColUpdate
(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
' Êý ¾Ý ÐÞ ¸Ä Ç° ´¥ ·¢ ¸Ã Ê ¼þ
On Error GoTo errHandler:
BeginTrans
If MsgBox(" È· ʵ Òª ÐÞ ¸Ä
Õâ Ò» ÄÚ ÈÝ £¿", vbQuestion + vbYesNo) = vbYes Then
CommitTrans
Else
Rollback
Data1.Refresh
End If
errHandler:
Select Case Err
Case 0
Response = 0
Case Else
MsgBox (Error)
Exit Sub
End Select
End Sub
Private Sub Form_Load()
' ÔÚ ´° Ìå ×° Èë ʱ£¬ Íø ¸ñ ÖÐ µÄ Êý ¾Ý ²» ¿É Ìí ¼Ó£¬ ÐÞ ¸Ä
DBGrid1.AllowAddNew = False
DBGrid1.AllowUpdate = False
End Sub
Private Sub Form_Resize()
On Error Resume Next
' µ± ´° Ìå µ÷ Õû ʱ »á µ÷ Õû Íø ¸ñ
DBGrid1.Height = Me.ScaleHeight - Data1.Height - cmd ɾ ³ý.Height - 30
End Sub
ÔÚ¹¤³ÌÖÐÌí¼ÓÒ»¸ö´°Ì壬ÔÚ´°ÌåÉÏ»6¸ö±êÇ©£¬1¸öÃüÁî°´Å¥£¨±êÌâΪ¡° È·ÈÏ¡±£¬Ãû³ÆΪ
cmd
È·ÈÏ£©£¬3¸öÎı¾¿òºÍ1¸ö×éºÏ¿ò¡£
ÔÚ´°ÌåµÄÉùÃ÷²¿·ÝÊäÈëÒÔÏ´úÂ룺
' Éù Ã÷ ´° Ìå ²ã ±ä Á¿
Dim rodbs As Database
Dim strDB As String, strRoDB As String, strCn As String, strTdf As String
Dim linkTdfName As String
±à д Èç Ï Ê ¼þ ¹ý ³Ì£º
Private Sub cmd È· ÈÏ_Click()
On Error GoTo errHandler:
strDB = text2.Text
' ±¾ µØ Êý ¾Ý ¿â Ãû ¼° · ¾¶
linkTdfName = Text3.Text
' ±¾ µØ Êý ¾Ý ¿â ÖРР½¨ µÄ Á´ ½Ó Ô¶ ³Ì ±í µÄ ±í Ãû
strCn = strRoDB ' Á¬ ½Ó ×Ö ·û ´®
strTdf = Combo1.Text ' Ö¸ ¶¨ Ô¶ ³Ì Êý ¾Ý ¿â ÖÐ Òª ·Ã ÎÊ µÄ ±í
' µ÷ ÓÃLinkTable ¹ý ³Ì
Call LinkTable(strDB, strRoDB, strCn, strTdf, linkTdfName)
' µ÷ ÓÃrst_display ¹ý ³Ì
Call rst_display(strDB, linkTdfName, Form1)
Form2.Hide
Form1.Show
Form1.Caption = " Ô¶ ³Ì Êý ¾Ý£SERIOUS INTERNAL INDIGESTION CLASS 13
í ¼Ó¡±£¬¡° ɾ ³ý¡±£¬¡° ÐÞ ¸Ä¡± ¿Ø ¼þ
Form1.cmdAdd.Visible = True
Form1.cmdDel.Visible = True
Form1.cmdModify.Visible = True
errHandler:
Select Case Err
Case 0
Response = 0
Case Else
MsgBox (Error + vbr + " ÖØ ÐÂ Êä Èë")
Exit Sub
End Select
End Sub
Private Sub Combo1_GotFocus()
strRoDB = text1.Text ' Ö¸ ¶¨ Ô¶ ³Ì Êý ¾Ý ¿â Ãû ¼° · ¾¶
Set rodbs = OpenDatabase(strRoDB) ' ´ò ¿ª Ô¶ ³Ì Êý ¾Ý ¿â
' ɾ ³ýcombo1 ÖÐ µÄ ÄÚ ÈÝ
If Combo1.ListCount >= 1 Then
For i = Combo1.ListCount - 1 To 0 Step -1
Combo1.RemoveItem i
Next i
End If
' °Ñ Êý ¾Ý ¿â ÖÐ µÄ ±í Ãû ¼Ó µ½combo1 ÖÐ
For i = 0 To rodbs.TableDefs.Count - 1
Combo1.AddItem rodbs.TableDefs(i).Name
Next i
End Sub
--
ÒԿƼÆΪ±¾,ÒÔ²úÒµ±¨¹ú!
³¬Ô½×ÔÎÒ,·ÉÔ¾ÎÞÏÞ!
¡ù À´Ô´:¡¤¹þ¹¤´ó×϶¡Ïã bbs.hit.edu.cn¡¤[FROM: 202.118.235.249]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º2.795ºÁÃë