Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\data\XXX.mdb;" _
& "Persist Security Info=False"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select age from name"
Adodc1.Refreshtext1.text = adodc1.recordset!age
rs.Open scstr, connstr
While Not rs.EOF And Not rs.BOF
colvalue = "'"
For i = 0 To rs.Fields.Count - 2 /**rs(i)代表记录的第i个字段
If IsNull(rs(i).Value) Then
colvalue = colvalue & "','"
Else
colvalue = colvalue & rs(i) & "','"
End If
Next
If IsNull(rs(rs.Fields.Count - 1)) Then
colvalue = colvalue & "'"
Else
colvalue = colvalue & rs(rs.Fields.Count - 1) & "'"
End If
List2.AddItem rs(
rs.MoveNext
Wend
rs.Close
scstr 是查询语句如:select ......connstr 是连接串"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\data\XXX.mdb Persist Security Info=False"如果已知字段名:
rs("age") 或 rs("age").value
如果你只取一个记录的值可以使用SQL
select age form name where 另外约束这字段
也可以使用这个方法。
set db=dbengin.workspace(0).opendatabase("数据库名")
set rs=db.openrecordset("name")
dim varTemp
with rs
move 记录号
vartemp=.fileds("age")
end with
可取得一个记录某个记录的字段值
dim con as ADODB.Connecttion
dim s as string
s="select age from name"
set con =New ADODB.Connecttion
set red=New ADODB.Recoredset
red.open s,con,4
Label1.Caption=red("age")