MSHFlexGrid的查找
这是一个查找代码
错误提示 "在对应所需名称或序数的集合中,未找到项目 "
Private Sub Command1_Click()
Dim yxbh As String
Dim COF As New ADODB.Recordset
Dim CON As New ADODB.Connection
Set COF = New ADODB.Recordset
CON.ConnectionString = cnn
CON.Open
yxbh = Text1.Text
Adodc1.ConnectionString = cnstr
Adodc1.RecordSource = "select * from clesses where 院系编号= ' " + yxbh + " ' "
Adodc1.Refresh
COF.Open "select * from clesses where 院系编号= ' " + yxbh + " ' ", CON
If Adodc1.Recordset.RecordCount> 0 Then
aa = Adodc1.Recordset.RecordCount
Form8.MSHFlexGrid1.Rows = aa
For i = 1 To aa
MSHFlexGrid1.CellAlignment = 4
MSHFlexGrid1.TextMatrix(i, 0) = COF.Fields(院系编号)
MSHFlexGrid1.TextMatrix(i, 1) = COF.Fields(院系名称)
MSHFlexGrid1.TextMatrix(i, 2) = COF.Fields(上级院系编号)
MSHFlexGrid1.TextMatrix(i, 3) = COF.Fields(院系职能描述)
i = i + 1
Next i
COF.Close
Form2.Show 1
Else
MsgBox "没有该院系编号 "
Text1.Text = " "
Text1.SetFocus
End If
End Sub
模块代码
Public Function cnstr() As String
cnstr = "provider=sqloledb;persist security info=false;user id=sa;initial catalog=studentsys "
End Function
Public Function cnn() As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open "driver={sql server};server=(local);database=studentsys;uid=sa;pwd= "
End Function
[解决办法]
COF.Fields( "院系编号 ")
都加上引号