- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2009-8-16 21:17:00
|
显示全部楼层
用ADO对象试试
- Public Function OpenConnForAccess(ByVal FileName As String) As ADODB.Connection
- Dim AdoConn As New ADODB.Connection
- With AdoConn
- .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
- .Open
- End With
- Set OpenConnForAccess = AdoConn
- End Function
- Public Function OpenConnForSqlServer(ByVal ServerName As String, ByVal UserId As String, ByVal PassWord As String, Optional ByVal DateBaseName As String = "") As ADODB.Connection
- Dim AdoConn As New ADODB.Connection
- Dim strConn As String
- With AdoConn
- strConn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=" & UserId & ";Password=" & PassWord & ";Data Source=" & ServerName
- If DateBaseName <> "" Then strConn = strConn & ";database=" & DateBaseName
- .ConnectionString = strConn
- .Open
- End With
- Set OpenConnForSqlServer = AdoConn
- End Function
- Public Function OpenConnForSqlServerByWin(ByVal ServerName As String, Optional ByVal DateBaseName As String = "") As ADODB.Connection
- Dim AdoConn As New ADODB.Connection
- Dim strConn As String
- With AdoConn
- strSql = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=" & ServerName
- If DateBaseName <> "" Then strConn = strConn & ";Initial Catalog=" & DateBaseName
- .ConnectionString = strConn
- .Open
- End With
- Set OpenConnForSqlServerByWin = AdoConn
- End Function
- Public Function OpenConnForOracle(ByVal ServerName As String, ByVal UserId As String, ByVal PassWord As String) As ADODB.Connection
- Dim AdoConn As New ADODB.Connection
- With AdoConn
- .ConnectionString = "Provider=MSDAORA.1;User ID=" & UserId & ";Password=" & PassWord & ";Persist Security Info=True;"
- .Open
- End With
- Set OpenConnForOracle = AdoConn
- End Function
- Public Function OpenRecordset(ByVal strSql As String, ByVal AdoConn As ADODB.Connection) As ADODB.Recordset
- Dim rs As New ADODB.Recordset
- With rs
- .CursorLocation = adUseClient
- .CursorType = adOpenDynamic
- .Open strSql, AdoConn, , , adCmdText
- End With
- Set OpenRecordset = rs
- End Function
- Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As ADODB.Connection)
- With AdoConn
- .BeginTrans
- .Execute tranSql
- .CommitTrans
- End With
- End Function
- 'strSql = "create table mytab1 (" & _
- ' "Id Counter primary key," & _
- ' "Name string(20) not null," & _
- ' "[Money] real," & _
- ' "Age int default 0," & _
- ' "[Date] DateTime);"
- 'RunTrans conn, strSql
|
|