读书人

vb 数据库 的操作,该如何解决

发布时间: 2012-12-17 09:31:40 作者: rapoo

vb 数据库 的操作
今天初学 数据库,用的是ADO 对象, 将数据库读入到 listview 中
问题1: 数据库里,有的数据为空,因此不能读入,shuo = rs.Fields(2),data.SubItems(2) = shuo
问题2:总函数不清楚,我是用的 for i=0 to 100 来读入数据的,而100 是小于 总行数的
而 用 for i=0 to n , n=rs.Count 出错
n=rs.MaxRecords n却为 0
n = rs.RecordCount n为 -1

请问各位一下,这是怎么一回事,在下 是初学者,请海涵!
[最优解释]
连接的cursorlocation属性必须设置为aduseclient
[其他解释]
问题1: 数据库里,有的数据为空,因此不能读入==>

shuo =iif(isnull(rs.Fields(2),0,rs.Fields(2))
data.SubItems(2) = shuo

问题2:总函数不清楚,我是用的 for i=0 to 100 来读入数据的,而100 是小于 总行数的
而 用 for i=0 to n , n=rs.Count 出错
n=rs.MaxRecords n却为 0
n = rs.RecordCount n为 -1
listview1.list
==>
with rs
if .recordcount>0 then
.movefirst
while not .eof
ListView1.ListItems.Add , , iif(isnull(.Fields(2),0,.Fields(2))
.movenext
wend
end if
end with

上面那个错误了
[其他解释]
问题1:shuo = rs.Fields(2) & ""
问题2:连接设置成客户端游标,for i=1 to rs.count

[其他解释]
问题1: 数据库里,有的数据为空,因此不能读入==>

shuo =iif(isnull(rs.Fields(2),0,rs.Fields(2))
data.SubItems(2) = shuo

问题2:总函数不清楚,我是用的 for i=0 to 100 来读入数据的,而100 是小于 总行数的
而 用 for i=0 to n , n=rs.Count 出错
n=rs.MaxRecords n却为 0
n = rs.RecordCount n为 -1
listview1.list
==>
with rs
if .recordcount>0 then
.movefirst
while not .eof
Private Sub Form_Load()
ListView1.ListItems.Add , , iif(isnull(.Fields(2),0,.Fields(2))
End Sub

.movenext
wend
end if
end with

[其他解释]
http://download.csdn.net/detail/veron_04/3827200
http://download.csdn.net/detail/veron_04/3154111
[其他解释]
设置后 那两个问题 也没解决啊,你能说得 具体点 么
[其他解释]
问题2 总行数,打错了,不是 总函数,不好意思

我想得到 数据库里 有多少行,然后 把它赋给 n
[其他解释]

引用:
问题1:shuo = rs.Fields(2) & ""
问题2:连接设置成客户端游标,for i=1 to rs.count


我这样试过了, for i=1 to rs.count 弹出错误:对象不支持该属性或方法


[其他解释]
Set rs = New ADODB.Recordset ,for i=1 to rs.count 弹出错误:对象不支持该属性或方法,rs.count 不对啊

读书人网 >VB

热点推荐