VB中一个COMMAND和2个TEXT控件~SLQ数据库~怎么样在text1中输入一个数据~点击COMMAND 输出数据在TEXT2中 20
1个回答
展开全部
Option Explicit
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim txtsql As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mydata.mdb;Persist Security Info=False" '设置链接ACCESS数据库字符串
cn.Open '连接数据库
Dim s As String
s = Text1.Text
txtsql = "select * from admin where id =" & s & " " '从表admin中查询,条件是id = s = text1.text
Set rs = cn.Execute(txtsql)
Text2.Text = rs.Fields(1) '将对应的结果输出到text2中
End Sub
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim txtsql As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mydata.mdb;Persist Security Info=False" '设置链接ACCESS数据库字符串
cn.Open '连接数据库
Dim s As String
s = Text1.Text
txtsql = "select * from admin where id =" & s & " " '从表admin中查询,条件是id = s = text1.text
Set rs = cn.Execute(txtsql)
Text2.Text = rs.Fields(1) '将对应的结果输出到text2中
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询