excel VBA动态链接数据库
时间:2021-07-01 10:21:17
帮助过:2人阅读
‘链接数据库
Set Cnn = CreateObject(
"ADODB.Connection")
Set rt = CreateObject(
"ADODB.Recordset")
Cnn.ConnectionString =
"Provider = SQLOLEDB;User ID= ;password=;Data Source=;Initial Catalog = "
Cnn.Open
Sql =
"SELECT TOP 1 Pmax FROM dbo where ID=‘" & SID &
"‘ order by hDateTime desc"
‘获取记录集
Set rt =
Cnn.Execute(Sql)
‘根据字段获取值
result = CStr(rt(
"Pmax"))
GETPMAX =
result
‘关闭记录集
rt.Close
‘关闭数据库链接,释放资源
Cnn.Close
End Function
excel VBA动态链接数据库
标签:class des rom exce hda bsp VID sql OLE