求教:ADO访问记录字段值有几种方法???

vpro 2003-02-14 05:21:03
_Recordset rs;
...
我知道的有两种:
rs->Fields->GetItem(_variant_t("姓名"))->Value = _bstr_t("阿三");

_variant_t var;
var = rs->GetCollect(_variant_t("姓名"));
两种方法有什么区别?推荐哪个?还有其它方法吗?
...全文
40 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cowgirl 2003-03-22
  • 打赏
  • 举报
回复
up,你这不是vc的数据库访问程序,是vb中的吧。虽然很相识,但会误导别人的。
xkcobj 2003-02-14
  • 打赏
  • 举报
回复
Public Sub ValueX()

Dim rstEmployees As ADODB.Recordset
Dim fldLoop As ADODB.Field
Dim prpLoop As ADODB.Property
Dim strCnn As String

' 使用雇员表的数据打开记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstEmployees = New ADODB.Recordset
rstEmployees.Open "employee", strCnn, , , adCmdTable

Debug.Print "Field values in rstEmployees"
' 枚举雇员表的字段集合。
For Each fldLoop In rstEmployees.Fields
' 由于值是字段对象的默认属性,
' 所以此处实际关键字的使用是可选的。
Debug.Print " " & fldLoop.Name & " = " & fldLoop.Value
Next fldLoop

Debug.Print "Property values in rstEmployees"
' 枚举记录集对象的属性集合。
For Each prpLoop In rstEmployees.Properties
' 由于值是属性对象的默认属性,
' 所以此处实际关键字的使用是可选的。
Debug.Print " " & prpLoop.Name & " = " & prpLoop.Value
Next prpLoop

rstEmployees.Close

End Sub
xkcobj 2003-02-14
  • 打赏
  • 举报
回复
Sub datashape()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rstTitleAuthor As New ADODB.Recordset

cnn.Provider = "MSDataShape"
cnn.Open "Data Provider=MSDASQL;" & _
"DSN=vfox;uid=sa;pwd=vfox;database=pubs”
‘步骤 1
rst.StayInSync = FALSE
rst.Open "SHAPE {select * from authors}
APPEND ({select * from titleauthor}
RELATE au_id TO au_id) AS chapTitleAuthor",
cnn
‘步骤 2
While Not rst.EOF
Debug.Print rst("au_fname"), rst("au_lname"),
rst("state"), rst("au_id")
‘步骤 3
Set rstTitleAuthor = rst("chapTitleAuthor").Value
‘步骤 4
While Not rstTitleAuthor.EOF
Debug.Print rstTitleAuthor(0), rstTitleAuthor(1),
rstTitleAuthor(2), rstTitleAuthor(3)
rstTitleAuthor.MoveNext
Wend
rst.MoveNext
Wend
End Sub

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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