在线急等一个查询问题!!!

bluesanke 2003-03-25 01:17:01
我有一个界面中有n个text框,对应着n个数据,现在我只对一个数据进行查询,查询结果是如果找到这个数据,那末界面里的其它数据也和表里的数据相连!
求用sql编写的这段查询代码,最好是能加一些注释
...全文
28 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyu5188 2003-03-28
  • 打赏
  • 举报
回复
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
rst.Open ("Select * from XXX where 字段名='" & Trim(text1.Text) & "'")
text2.text = rst.Fields(1)'提取字段1的值给文本框2
rst.Close
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\XXX.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub
wamlaw 2003-03-28
  • 打赏
  • 举报
回复
例如有3个text对应3个数据
text1进行查询
sql=”select text1对应的字段,text2对应的字段,text3对应的字段 from table where text1对应的字段=” & “’”&trim(text1.text)&”’”
set rs=cn.execute(sql)
if isnull(rs.field(0)) =false then
text1.text=rs.field(“text1对应的字段”)
text2.text=rs.field(“text2对应的字段”)
text3.text=rs.field(“text3对应的字段”)
end if
pcwak 2003-03-28
  • 打赏
  • 举报
回复
Dim con As Connection
Dim rst As Recordset

Private Sub cmdOK_Click()
rst.Open ("Select * from qq where 用户='" & Trim(txtName.Text) & "'")

If rst.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtName.Text = ""
txtpwd.Text = ""
Else
txtpwd.Text = rst.Fields(1)
End If
rst.Close
End Sub
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
With con
.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
.Open
End With
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.ActiveConnection = con
End Sub
bluesanke 2003-03-28
  • 打赏
  • 举报
回复
那查到编号后,怎样做把和编号在同一表中的数据送到对应的text框中呀!给点代码吧
tmat 2003-03-25
  • 打赏
  • 举报
回复
dim Str as string '定义字符串变量
Str=文本框名.text
select from 表名 where 查询的字段名 '" & Str & "'
最后加上 如:
文本框名称.text=对象名称("字段名") '对文本框赋值


pcwak 2003-03-25
  • 打赏
  • 举报
回复
select * from 表名 where 字段='"& text1 &"'

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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