有关下标越界问题
Private Sub update()'判断是否连接数据库
If conn.State = adStateOpen Then
conn.Close
End If
conn.Open ConnectionString
If rs.State = adStateOpen Then
rs.Close
End If
rs.CursorLocation = adUseClient
SQL = "select * from 计量单位表 "
rs.Open SQL, conn, adOpenKeyset, adLockPessimistic
Adodc1.ConnectionString = ConnectionString
Adodc1.Visible = False
Adodc1.RecordSource = SQL + " order by " + "编号"
Set DataGrid1.DataSource = Adodc1
Adodc1.Refresh
'Set DataGrid1.DataSource = rs
initdatagrid1 '调用函数
End Sub
Private Sub initdatagrid1() '设置DataGrid1属性
'设置各列宽度
DataGrid1.Columns(0).Width = 2100
DataGrid1.Columns(1).Width = 2100
DataGrid1.Columns(2).Width = 2100
'设置锁定
DataGrid1.Columns(0).Locked = True
DataGrid1.Columns(1).Locked = True
DataGrid1.Columns(2).Locked = True
DataGrid1.HeadLines = 2
DataGrid1.rowheight = 270 '行高度
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
If Toolbar1.Buttons(2).Value = tbrPressed Then
Text1.Enabled = False '限定不能输入
Text1.Text = DataGrid1.Columns(0).Value
Text2.Text = DataGrid1.Columns(1).Value
Text3.Text = DataGrid1.Columns(2).Value
'[bo]提示这里错误 下标越界[/bo]我改成这样Text3.Text = Adodc1.Recordset(2) 为什么就可以了 是哪设置错误?高手赐教End If
If Toolbar1.Buttons(3).Value = tbrPressed Then
Text1.Enabled = False '限定不能输入等
Text2.Enabled = False
Text1.Text = DataGrid1.Columns(0).Value
Text2.Text = DataGrid1.Columns(1).Value
Text3.Text = Adodc1.Recordset(2)
End If
End Sub
Private Sub Form_Load()
update
End Sub