Dim rs As New ADODB.Recordset '创建指针集
Private Sub Form_Load()
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0Data Source=C:\Users\lbj\Desktop\test.mdb" '连接字符串
End SubPrivate Sub Form_Unload(Cancel As Integer)
cn.Close '关闭数据库对象
End SubPrivate Sub Text1_Change()
c = "select year from info where name='" &Text1.Text &"'" '查询语句
rs.Open c, cn, 3, 3 '查询
Text2.Text = rs.Fields(0) '赋值过去
rs.Close '关闭对象
End Sub
实时查询 只有输入到相应的名字才会显示年龄
必须安装mysql的驱动才行,不管是vb还是c++都需要这个驱动。代码如下:
public
function
exemysql(byval
sql
as
string)
as
adodb.recordset
sql
=
trim$(sql)
set
conn
=
new
adodb.connection
set
rs
=
new
adodb.recordset
conn.open
"driver=mysql
odbc
3.51
driver"
&
_
"server=服务器地址"
&
_
"port=3306"
&
_
"database=数据库名"
&
_
"uid=用户名"
&
_
"pwd=密码"
conn.defaultdatabase
=
"数据库名"
conn.cursorlocation
=
aduseclient
set
rs.activeconnection
=
conn
rs.locktype
=
adlockbatchoptimistic
rs.cursortype
=
adopenkeyset
rs.open
sql
set
exesql
=
rs
set
rs
=
nothing
set
conn
=
nothing
end
function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)