主题:VB与SQL连接的一个问题
Private Sub Form_Load()
Set objcn = New Connection '设置连接对象
With objcn
.Provider = "SQLOLEDB"
.ConnectionString = "user id=sa;pwd=123;data source=(local);" & "intial catalog=教学信息"
.Open
End With
Set objteacher = New Recordset '设置objteacher对象
With objteacher
Set .ActiveConnection = objcn '设置数据库连接
.CursorLocation = adUseClient '使用客户端游标
.CursorType = adOpenStatic '使用静态游标
'获取教师信息
[color=FF0000] .Open "select 教师信息.*,系名称 from 教师信息,系部信息 where 教师信息.系编号 = 系部信息.系编号"[/color]
End With
'获取学生信息
Set objscore = New Recordset
With objscore
Set .ActiveConnection = objcn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
'获取学生信息
.Open "select 课编号,学生 as 学生编号,姓名,成绩" & "from 选课记录,学生信息" & "where 选课记录.学生=学生信息.编号" & "order by 学生编号"
'设定筛选条件为空字符串
.Filter = "课程号="""
End With
Set dglist.DataSource = objscore
dglist.Columns(0).Visible = False
'获取课程信息
Set objclass = New Recordset
With objclass
Set .ActiveConnection = objcn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Open "select 课编信息.编号 as 课编号,名称,学分,姓名,教师编号.编号 as 教师编号" & "from 课程信息,教师信息" & "where 课程信息.教师=教师信息.编号" '获取课程信息
'建立课程列表
If .RecordCount > 0 Then
.MoveFirst
While Not .EOF
cmbnum.AddItem .Fields("课编号")
.MoveNext
Wend
End If
End With
End Sub
红色的地方它一直提示我 对象名 '教师信息' 无效!!!那位高手能帮帮小弟,急~~