vb 操作多张数据表
'连接数据库strsql="provider=Micfosoft.Jet.OLEDB.4.0;DataSource="&App.Path&"/Result.mdb;Per...
'连接数据库
strsql="provider=Micfosoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/Result.mdb;Persist Security Info=False"
If con.State<>asStateClosed Then con.Close
con.Open strsql
'打开数据表
'打开表Calibrations
tmpstr="select * from Calibrations"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
'打开表Meters
......
'打开表Tests
......
'按要求将上述3张表的部分内容整合到一张表
tmpstr="select Calibrations.CalibrationId,Meters.Position,Tests.LabTemperature from (Calibrations LEFT JOIN Meters ON (Calibrations.CalibrationId=Meters.CalibrationId) AND (Calibrations.EquipmentId=Meters.EquipmentId)) LEFT JOIN Tests ON (Meters.CalibrationId=Tests.CalibrationId) AND (Meters.EquipmentId=Tests.EquipmentId) AND (Meters.Position=Tests.Position)"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
运行时提示,对象'Open'的方法'_Recordset'失败
感觉以上操作数据库的方法一次只能操作一张表,不能同时操作多张表。
也许表述不太清楚,但我想看过代码的各位应该都能明白我的意思。
请各位大神不吝赐教。 展开
strsql="provider=Micfosoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/Result.mdb;Persist Security Info=False"
If con.State<>asStateClosed Then con.Close
con.Open strsql
'打开数据表
'打开表Calibrations
tmpstr="select * from Calibrations"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
'打开表Meters
......
'打开表Tests
......
'按要求将上述3张表的部分内容整合到一张表
tmpstr="select Calibrations.CalibrationId,Meters.Position,Tests.LabTemperature from (Calibrations LEFT JOIN Meters ON (Calibrations.CalibrationId=Meters.CalibrationId) AND (Calibrations.EquipmentId=Meters.EquipmentId)) LEFT JOIN Tests ON (Meters.CalibrationId=Tests.CalibrationId) AND (Meters.EquipmentId=Tests.EquipmentId) AND (Meters.Position=Tests.Position)"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
运行时提示,对象'Open'的方法'_Recordset'失败
感觉以上操作数据库的方法一次只能操作一张表,不能同时操作多张表。
也许表述不太清楚,但我想看过代码的各位应该都能明白我的意思。
请各位大神不吝赐教。 展开
2个回答
展开全部
:'连接数据库
strsql="provider=Micfosoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/Result.mdb;Persist Security Info=False"
If con.State<>asStateClosed Then con.Close
con.Open strsql
'打开数据表
'打开表Calibrations
tmpstr="select * from Calibrations"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
'打开表Meters
......
'打开表Tests
......
'按要求将上述3张表的部分内容整合到一张表
tmpstr="select Calibrations.CalibrationId,Meters.Position,Tests.LabTemperature from (Calibrations LEFT JOIN Meters ON (Calibrations.CalibrationId=Meters.CalibrationId) AND (Calibrations.EquipmentId=Meters.EquipmentId)) LEFT JOIN Tests ON (Meters.CalibrationId=Tests.CalibrationId) AND (Meters.EquipmentId=Tests.EquipmentId) AND (Meters.Position=Tests.Position)"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
运行时提示,对象'Open'的方法'_Recordset'失败
感觉以上操作数据库的方法一次只能操作一张表,不能同时操作多张表。
也许表述不太清楚,但我想看过代码的各位应该都能明白我的意思。
请各位大神不吝赐教。我来帮他解答
strsql="provider=Micfosoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/Result.mdb;Persist Security Info=False"
If con.State<>asStateClosed Then con.Close
con.Open strsql
'打开数据表
'打开表Calibrations
tmpstr="select * from Calibrations"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
'打开表Meters
......
'打开表Tests
......
'按要求将上述3张表的部分内容整合到一张表
tmpstr="select Calibrations.CalibrationId,Meters.Position,Tests.LabTemperature from (Calibrations LEFT JOIN Meters ON (Calibrations.CalibrationId=Meters.CalibrationId) AND (Calibrations.EquipmentId=Meters.EquipmentId)) LEFT JOIN Tests ON (Meters.CalibrationId=Tests.CalibrationId) AND (Meters.EquipmentId=Tests.EquipmentId) AND (Meters.Position=Tests.Position)"
If rsAccess.State<>adStateClosed Then rsAccess.Close
rsAccess.Open tmpstr,con,adOpenDynamic,adLockPessimistic
运行时提示,对象'Open'的方法'_Recordset'失败
感觉以上操作数据库的方法一次只能操作一张表,不能同时操作多张表。
也许表述不太清楚,但我想看过代码的各位应该都能明白我的意思。
请各位大神不吝赐教。我来帮他解答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询