上楼大哥,还是你一语点中,可以了,谢谢你了。
楼主的写程序时结构要清晰,
‘’要先连接数据库,再写打开数据源,一步步来,也好判断错误出在哪里?
Dim rs As New ADODB.Recordset '写入数据库是OK的
Dim cn As New ADODB.Connection
Dim strCn As String, strSQL As String
strCn = "Provider=sqloledb;server=.;Database=456;Uid=sa;Pwd=;"
cn.Open strCn ‘先连接数据库’
rs.Open "select * from yuangong where ygname='李**'", cn, 1, 3 ‘再打开表’