Thng tin: My bay ph?n l?c OLE DB nh cung c?p phin b?n 4.0 h? tr? ch?n @@ Identity

D?ch tiu ? D?ch tiu ?
ID c?a bi: 232144 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

TM T?T

Nh cung c?p my bay ph?n l?c OLE DB Phin b?n 4.0 h? tr? truy v?n ch?n @@ danh tnh cho php b?n ? l?y gi tr? c?a l?nh v?c t? ?ng-tng ?c t?o ra trn k?t n?i c?a b?n. Auto-tng gi tr? ?c s? d?ng trn cc k?t n?i c s? d? li?u c?a b?n khng lm ?nh h?ng ?n k?t qu? truy v?n chuyn ngnh ny. Tnh nng ny lm vi?c v?i c s? d? li?u my bay ph?n l?c 4.0, nhng khng ph?i v?i ?nh d?ng c? hn.

THNG TIN THM

M? sau y minh ch?ng b?ng cch s? d?ng ch?n @@ danh tnh ? l?y gi tr? c?a l?nh v?c m?i ?c chn vo auto-tng. o?n m? ny c?ng bao g?m m? ? t?o ra b?ng cho cc truy v?n.
Dim cnDatabase As ADODB.Connection
Dim rsNewAutoIncrement As ADODB.Recordset
Dim strConn As String
Dim strSQL As String
Dim strPathToMDB As String
   
strPathToMDB = "C:\NewJet4.MDB"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & strPathToMDB & ";"
Set cnDatabase = New ADODB.Connection
    cnDatabase.Open strConn
    
    strSQL = "CREATE TABLE AutoIncrementTest " & _
             "(ID int identity, Description varchar(40), " & _
             "CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))"
    cnDatabase.Execute strSQL, , adCmdText + adExecuteNoRecords
    
    strSQL = "INSERT INTO AutoIncrementTest " & _
             "(Description) VALUES ('AutoIncrement Test')"
    cnDatabase.Execute strSQL, , adCmdText + adExecuteNoRecords
    
    strSQL = "SELECT @@Identity"
    Set rsNewAutoIncrement = New ADODB.Recordset
    rsNewAutoIncrement.Open strSQL, cnDatabase, adOpenForwardOnly, _
                            adLockReadOnly, adCmdText
    MsgBox "New Auto-increment value is: " & rsNewAutoIncrement(0).Value

    rsNewAutoIncrement.Close
    Set rsNewAutoIncrement = Nothing
    strSQL = "DROP TABLE AutoIncrementTest"
    cnDatabase.Execute strSQL, , adCmdText + adExecuteNoRecords
    cnDatabase.Close
Set cnDatabase = Nothing
				
Nh? vo tnh nng ny m?i ?c b? sung, b?n c th? th?y gi tr? v?a ?c thm vo auto-tng trong recordsets ActiveX Data Objects (ADO) pha khch hng c?a b?n trong ADO 2,1 v sau ny. Khi b?n g?i hng m?i ? cc nh cung c?p my bay ph?n l?c b?ng cch g?i C?p Nh?t ho?c UpdateBatch (ph? thu?c vo s? l?a ch?n c?a LockType), ?ng c con tr? ADO t?o ra m?t CHN vo truy v?n ? t?o d?ng m?i trong b?ng. N?u recordset ch?a m?t l?nh v?c t? ?ng-tng, ADO c?ng s? t?o ra m?t truy v?n ch?n @@ Identity ? l?y gi tr? ?c t?o ra cho l?nh v?c t? ?ng-tng . M? sau y ch?ng t? tnh nng ny:
Dim cnDatabase As ADODB.Connection
Dim rsNewAutoIncrement As ADODB.Recordset
Dim strConn As String
Dim strSQL As String
Dim strPathToMDB As String
    
strPathToMDB = "C:\NewJet4.MDB"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & strPathToMDB & ";"
    Set cnDatabase = New ADODB.Connection
    cnDatabase.Open strConn
    
    strSQL = "CREATE TABLE AutoIncrementTest " & _
             "(ID int identity, Description varchar(40), " & _
             "CONSTRAINT AutoIncrementTest_PrimaryKey PRIMARY KEY (ID))"
    cnDatabase.Execute strSQL, , adCmdText + adExecuteNoRecords

    strSQL = "SELECT ID, Description FROM AutoIncrementTest"
    Set rsNewAutoIncrement = New ADODB.Recordset
    rsNewAutoIncrement.CursorLocation = adUseClient
    rsNewAutoIncrement.Open strSQL, cnDatabase, adOpenStatic, _
                            adLockOptimistic, adCmdText
    rsNewAutoIncrement.AddNew
    rsNewAutoIncrement("Description").Value = "AutoIncrement Test"
    rsNewAutoIncrement.Update
    MsgBox "New Auto-increment value is: " & rsNewAutoIncrement(0).Value

    rsNewAutoIncrement.Close
    Set rsNewAutoIncrement = Nothing
    strSQL = "DROP TABLE AutoIncrementTest"
    cnDatabase.Execute strSQL, , adCmdText + adExecuteNoRecords
    cnDatabase.Close
Set cnDatabase = Nothing
				
B?n c th? t?o c s? d? li?u m?i Jet 4,0 b?ng cch s? d?ng Microsoft Access 2000 ho?c b?ng cch s? d?ng th vi?n ADOX ?c bao g?m v?i MDAC 2.1. ? s? d?ng th vi?n ny trong d? n Visual Basic c?a b?n, t?o ra m?t tham chi?u ?n Microsoft ADO Ext. 2.1 for Optical Mouse v an ninh. B?n c th? s? d?ng m? nh sau y ? t?o ra m?t c s? d? li?u my bay ph?n l?c 4,0 m?i:
Dim strPathToMDB As String
Dim catNewDatabase As ADOX.Catalog
    
    strPathToMDB = "C:\NewJet4.MDB"
    If Dir(strPathToMDB) <> "" Then
        Kill strPathToMDB
    End If
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & strPathToMDB & ";"
    Set catNewDatabase = New ADOX.Catalog
    catNewDatabase.Create strConn
    Set catNewDatabase = Nothing
				
? xc ?nh cc ?nh d?ng c?a c s? d? li?u Microsoft Access, ki?m tra cc ti s?n "ph?n l?c OLEDB:Engine ki?u" nng ?ng trong b? su t?p thu?c tnh c?a ?i t?ng k?t n?i. Cc ti s?n s? tr? v? m?t gi tr? c?a 5 cho my bay ph?n l?c 4.x c s? d? li?u. o?n m? sau y th? hi?n b?ng cch s? d?ng b?t ?ng s?n:
Dim cnDatabase As ADODB.Connection
Dim strConn As String
Dim strPathToMDB As String
    
strPathToMDB = "C:\NewJet4.MDB"
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & strPathToMDB & ";"
Set cnDatabase = New ADODB.Connection
    cnDatabase.Open strConn
    If cnDatabase.Properties("Jet OLEDB:Engine Type").Value = 5 Then
        MsgBox "Jet 4.0 database"
    Else
        MsgBox "Not a Jet 4.0 database"
    End If
    cnDatabase.Close
Set cnDatabase = Nothing
				

THAM KH?O

Truy c?p d? li?u Microsoft SDK; t?m ki?m trn: "Thu?c tnh Provider-Defined"; ch? ?: "dbpropset_jetoledb_dbinit"

Thu?c tnh

ID c?a bi: 232144 - L?n xem xt sau cng: 21 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
T? kha:
kbdatabase kbinfo kbjet kbmt KB232144 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:232144

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com