Public strSQL Public strConnectionString Public objRecordset Public objConnection Public objCommand
Sub OpenDataBase_Config strConnectionString = "Provider=MSDASQL;DSN=ODBC_BD06_A_DC00;UID=BDAndon;PWD=BDAndon;" ’DSN为ODBC链接的名称,UID是用户名,PWD是密码 Set objConnection = CreateObject("ADODB.Connection") objConnection.ConnectionString = strConnectionString objConnection.Open Set objCommand = CreateObject("ADODB.Command") End Sub
Sub CloseDataBase_Config Set objCommand = Nothing objConnection.Close Set objConnection = Nothing End Sub
调用时的方法:
dim Type OpenDataBase_Config
strSQL = "SELECT Top 1 * FROM Table_AndonStyle_Style_Config WHERE (AndonID = "&AndonNum.read&") ORDER BY SetupTime desc" With objCommand .ActiveConnection = objConnection .CommandText = strSQL End With
Set objRecordset = objCommand.Execute
'************** Read **************
Type=objRecordset.Fields(2).Value
'************ close datebace *********** OpenDataBase_Config
看了楼上的程序,有几个疑问,我是新手,呵呵 1.strSQL = "SELECT Top 1 * FROM Table_AndonStyle_Style_Config WHERE (AndonID = "&AndonNum.read&") ORDER BY SetupTime desc" 中Top 1是什么意思? 我记得在VB中SQL语句用SELECT * FROM 就可以了?我弄过VB,对VBS不太懂 2.Type=objRecordset.Fields(2).Value 是把表中的哪个数据赋给Type啊? 3.如果要修改数据库中的某个值,怎么写.