由于特殊原因需要用DAO访问Sqlserver数据库,求各位老兄给个例子.
不知道对Dao的版本是否有限制,先谢了。
不知道对Dao的版本是否有限制,先谢了。
解决方案 »
- vb类中如何调用form里面的变量或者function。
- vb编程连接sqlserver2005,为何连不上呀?是不是要装2005的驱动呀?如何装?
- 在DragDrop事件中如何确定放置的Item是从哪个控件拖动过来的?
- ACCESS + VB
- VB中,知道控件的句柄,怎么知道控件的名字。
- 谁来帮帮我,HELP!!!!
- 求一试管控件, 里面的药水高度可随时控制
- 关于视频的二次开发
- 求助:DataGrid控件不显示数据库的最后一行记录?
- 怎样用vb把数据库(Access)压缩和修复
- 关于数据库的问题
- 请问如何在Datagrid中选中一整行,按下一个键,datagrid的当前行被整个选中,注意不是用鼠标点击
Set cn = OpenDatabase("", 0, 0, "ODBC;Driver=SQL Server;server=155.29.12.15;UID=sa;PWD=11;DATABASE=deg") 以下是一段帮助中的示例:
Connection Object, Connections Collection ExampleThis example demonstrates the Connection object and Connections collection by opening a Microsoft Jet Database object and two ODBCDirect Connection objects and listing the properties available to each object.Sub ConnectionObjectX() D.....................
...........
Set cn = OpenDatabase("", 0, 0, "ODBC;Driver=SQL Server;server=155.29.12.15;UID=sa;PWD=11;DATABASE=deg") 以下是一段帮助中的示例:
Connection Object, Connections Collection ExampleThis example demonstrates the Connection object and Connections collection by opening a Microsoft Jet Database object and two ODBCDirect Connection objects and listing the properties available to each object.Sub ConnectionObjectX() Dim wrkJet as Workspace
Dim dbsNorthwind As Database
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim conPubs2 As Connection
Dim conLoop As Connection
Dim prpLoop As Property ' Open Microsoft Jet Database object.
Set wrkJet = CreateWorkspace("NewJetWorkspace", _
"admin", "", dbUseJet)
Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb") ' Create ODBCDirect Workspace object and open Connection
' objects.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
"admin", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("Connection1", , , _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
Set conPubs2 = wrkODBC.OpenConnection("Connection2", , _
True, "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers") Debug.Print "Database properties:" With dbsNorthwind
' Enumerate Properties collection of Database object.
For Each prpLoop In .Properties
On Error Resume Next
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop.Value
On Error GoTo 0
Next prpLoop
End With ' Enumerate the Connections collection.
For Each conLoop In wrkODBC.Connections
Debug.Print "Connection properties for " & _
conLoop.Name & ":" With conLoop
' Print property values by explicitly calling each
' Property object; the Connection object does not
' support a Properties collection.
Debug.Print " Connect = " & .Connect
' Property actually returns a Database object.
Debug.Print " Database[.Name] = " & _
.Database.Name
Debug.Print " Name = " & .Name
Debug.Print " QueryTimeout = " & .QueryTimeout
Debug.Print " RecordsAffected = " & _
.RecordsAffected
Debug.Print " StillExecuting = " & _
.StillExecuting
Debug.Print " Transactions = " & .Transactions
Debug.Print " Updatable = " & .Updatable
End With Next conLoop dbsNorthwind.Close
conPubs.Close
conPubs2.Close
wrkJet.Close
wrkODBC.CloseEnd Sub
Dim conPubs As Connection
Dim conPubs2 As Connection
Dim conPubs3 As Connection
Dim conLoop As Connection ' Create ODBCDirect Workspace object.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
"admin", "", dbUseODBC) ' Open Connection object using supplied information in
' the connect string. If this information were
' insufficient, you could trap for an error rather than
' go to an ODBC Driver Manager dialog box.
MsgBox "Opening Connection1..."
Set conPubs = wrkODBC.OpenConnection("Connection1", _
dbDriverNoPrompt, , _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers") ' Open read-only Connection object based on information
' you enter in the ODBC Driver Manager dialog box.
MsgBox "Opening Connection2..."
Set conPubs2 = wrkODBC.OpenConnection("Connection2", _
dbDriverPrompt, True, "ODBC;DSN=Publishers;") ' Open read-only Connection object by entering only the
' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening Connection3..."
Set conPubs3 = wrkODBC.OpenConnection("Connection3", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;") ' Enumerate the Connections collection.
For Each conLoop In wrkODBC.Connections
Debug.Print "Connection properties for " & _
conLoop.Name & ":" With conLoop
' Print property values by explicitly calling each
' Property object; the Connection object does not
' support a Properties collection.
Debug.Print " Connect = " & .Connect
' Property actually returns a Database object.
Debug.Print " Database[.Name] = " & _
.Database.Name
Debug.Print " Name = " & .Name
Debug.Print " QueryTimeout = " & .QueryTimeout
Debug.Print " RecordsAffected = " & _
.RecordsAffected
Debug.Print " StillExecuting = " & _
.StillExecuting
Debug.Print " Transactions = " & .Transactions
Debug.Print " Updatable = " & .Updatable
End With Next conLoop conPubs.Close
conPubs2.Close
conPubs3.Close
wrkODBC.CloseEnd Sub
Dim dbsPubs As Database
Dim prpLoop As Property ' Create Microsoft Jet Workspace object.
Set wrkMain = CreateWorkspace("", "admin", "", dbUseJet) ' Open a Database object based on information in
' the connect string.
Set dbsPubs = wrkMain.OpenDatabase("Publishers", _
dbDriverNoPrompt, False, _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers") ' Enumerate the Properties collection of the Database
' object.
With dbsPubs
Debug.Print "Database properties for " & _
.Name & ":" On Error Resume Next
For Each prpLoop In .Properties
If prpLoop.Name = "Connection" Then
' Property actually returns a Connection object.
Debug.Print " Connection[.Name] = " & _
.Connection.Name
Else
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
End If
Next prpLoop
On Error GoTo 0 End With dbsPubs.Close
wrkMain.CloseEnd SubThe NewDatabaseCode example opens a Connection object in an ODBCDirect workspace. It then assigns the Database property of the Connection object to an object variable with the same name as the data source in the old procedure. None of the subsequent code has to be changed as long as it doesn't use any features specific to Microsoft Jet workspaces.Sub NewDatabaseCode() Dim wrkMain As Workspace
Dim conPubs As Connection
Dim dbsPubs As Database
Dim prpLoop As Property ' Create ODBCDirect Workspace object instead of Microsoft
' Jet Workspace object.
Set wrkMain = CreateWorkspace("", "admin", "", dbUseODBC) ' Open Connection object based on information in
' the connect string.
Set conPubs = wrkMain.OpenConnection("Publishers", _
dbDriverNoPrompt, False, _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
' Assign the Database property to the same object
' variable as in the old code.
Set dbsPubs = conPubs.Database ' Enumerate the Properties collection of the Database
' object. From this point on, the code is the same as the
' old example.
With dbsPubs
Debug.Print "Database properties for " & _
.Name & ":" On Error Resume Next
For Each prpLoop In .Properties
If prpLoop.Name = "Connection" Then
' Property actually returns a Connection object.
Debug.Print " Connection[.Name] = " & _
.Connection.Name
Else
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
End If
Next prpLoop
On Error GoTo 0 End With dbsPubs.Close
wrkMain.CloseEnd Sub