我这个datagrid的错误到底是什么?

alexgeng 2003-01-08 11:54:21
我建立了一个datagrd控件和一个adodc控件绑定后,
在DataGrid1_RowColChange事件中
有以下语句:Adodc1.Recordset.Move (DataGrid1.Row)
我想当按了某以个框后。会在adodc控件中自动转倒当前记录。
但马上在某几行按了后会出现,run time error"-2147217842"
然后我屏蔽了这句话后,在某几行按下会出现error occured while tring to set current row
...全文
48 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
alexgeng 2003-01-08
  • 打赏
  • 举报
回复
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Text1.Text = Adodc1.Recordset.Fields(17)‘出错的行。
Text5.Text = DataGrid1.Row
'Adodc1.Recordset.Move (DataGrid1.Row)
End Sub
Private Sub Form_Load()
Dim str As String
str = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\tspf.dll"
Adodc1.ConnectionString = str
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from tspf order by pfid"
Adodc1.Refresh
当没有出错行是。能够随便点击任一行,可以得到当前的row值。
但如果加上出错行是。点击某些行会报错,error occured while tring to set current row。。。。很奇怪阿。。。。大家请帮帮忙阿。
alexgeng 2003-01-08
  • 打赏
  • 举报
回复
就是为什么在datagrid控件中不能点选某些行。他会报错。。这是什么问题阿?该怎么解决?
heipifeng 2003-01-08
  • 打赏
  • 举报
回复
不大明白你的意思
of123 2003-01-08
  • 打赏
  • 举报
回复
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Text1.Text = Adodc1.Recordset.Fields(17)‘出错的行。
Text5.Text = DataGrid1.Row
'Adodc1.Recordset.Move (DataGrid1.Row)
End Sub

1 text1可以直接绑定
2 DataGrid1.Row是当前行在DataGrid1当前页中的行序号
3 Adodc1.Recordset.Move n 是从当前记录向前移n行。不明白你的Adodc1.Recordset.Move (DataGrid1.Row)是想干什么。
alexgeng 2003-01-08
  • 打赏
  • 举报
回复
谢谢了。
skyzxg 2003-01-08
  • 打赏
  • 举报
回复
你是乎没必要写代码。由于DataGrid已经与Adodc关联上了
你点击DataGrid,Adodc.Recordset也就指向了你所选的那条纪录

而你添加的东西也是画蛇添足,即使不报错,也不会得出你想要的东西

你的报错,是否是字段超出17,或者类型不对呢
holydiablo 2003-01-08
  • 打赏
  • 举报
回复
在Adodc1.Recordset.Fields(17)这个之前看一看
Adodc1.Recordset.recordcount是不是为0
alexgeng 2003-01-08
  • 打赏
  • 举报
回复
自己up

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧