VB 从数据库中读出的记录怎样分别取得其各个字段的值
rs.Open"select序号,商品号,商品名称,规格,单价from商品入库信息表where序号='"&Trim(Me.Text1.Text)&"'",db,adOpe...
rs.Open "select 序号,商品号,商品名称,规格,单价 from 商品入库信息表 where 序号='" & Trim(Me.Text1.Text) & "' ", db, adOpenStatic, adLockReadOnly 请问一下 用上面的语句 读出记录后 我想分别将 :序号,商品号,商品名称,规格,单价 的值赋到 几个Text文本框里 应该怎样写?
展开
3个回答
2013-11-25
展开全部
给你一个例子 看一下就应该懂了
Private Sub cmdRead_Click()
Dim RS As ADODB.Recordset
Dim tSql As String
Dim I As Integer
Set RS = New ADODB.Recordset
tSql = "Select * From TestUser Where XueHao=" & Trim(txtID.Text)
RS.Open tSql, CN, adOpenStatic, adLockOptimistic
If RS.RecordCount > 0 Then
txtName.Text = RS.Fields("XingMing")
txtScore.Text = RS.Fields("ChengJi")
Else
MsgBox "数据库中未找到相应记录", vbOKOnly, "提示"
End If
Set RS = Nothing
End Sub
Private Sub Form_Load()
Set CN = New ADODB.Connection
'QQ.mdb需要指定全路径,如C:\qq.mdb,具体位置自己修改。
CN.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\QQ.mdb;Uid=Admin;Pwd="
txtID.Text = "": txtName.Text = "": txtScore.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set CN = Nothing
End Sub
Private Sub cmdRead_Click()
Dim RS As ADODB.Recordset
Dim tSql As String
Dim I As Integer
Set RS = New ADODB.Recordset
tSql = "Select * From TestUser Where XueHao=" & Trim(txtID.Text)
RS.Open tSql, CN, adOpenStatic, adLockOptimistic
If RS.RecordCount > 0 Then
txtName.Text = RS.Fields("XingMing")
txtScore.Text = RS.Fields("ChengJi")
Else
MsgBox "数据库中未找到相应记录", vbOKOnly, "提示"
End If
Set RS = Nothing
End Sub
Private Sub Form_Load()
Set CN = New ADODB.Connection
'QQ.mdb需要指定全路径,如C:\qq.mdb,具体位置自己修改。
CN.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\QQ.mdb;Uid=Admin;Pwd="
txtID.Text = "": txtName.Text = "": txtScore.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set CN = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询