在VB中如何实现按钮与数据库相连接`以及数据库的自动更新
在VB中如何实现按钮与数据库相连接`也就是假如说按钮A显示的字符为:AB点击后打开网页:www.XXX.COM应该如何实现?让软件按钮与数据库连接`如何让数据库的自动更新...
在VB中如何实现按钮与数据库相连接`
也就是假如说按钮A 显示的字符为 :AB 点击后打开网页 :www.XXX.COM 应该如何实现? 让软件按钮与数据库连接
`如何让数据库的自动更新
还有就是如何写代码让软件自动更新`` 展开
也就是假如说按钮A 显示的字符为 :AB 点击后打开网页 :www.XXX.COM 应该如何实现? 让软件按钮与数据库连接
`如何让数据库的自动更新
还有就是如何写代码让软件自动更新`` 展开
2个回答
2013-07-06
展开全部
ADO控件与数据库连接代码如下
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
'插入数据:
If rs.State <> adStateClosed Then '检查记录集状态
rs.Close
End If
rs.Open "insert into T_user(name,age) values('" & txtname.Text & "'," & txtage & ")", conn, adOpenDynamic, adLockBatchOptimistic
If rs.State <> adStateClosed Then
rs.Close
End If
'更新DataGrid1数据
rs.Open "select * from T_user", conn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Load()
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\hb\桌面\db1.mdb;Persist Security Info=False"
conn.CursorLocation = adUseClient '游标放在客户端
rs.CursorLocation = adUseClient
rs.Open "select * from T_user", conn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs.Close '释放
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
'插入数据:
If rs.State <> adStateClosed Then '检查记录集状态
rs.Close
End If
rs.Open "insert into T_user(name,age) values('" & txtname.Text & "'," & txtage & ")", conn, adOpenDynamic, adLockBatchOptimistic
If rs.State <> adStateClosed Then
rs.Close
End If
'更新DataGrid1数据
rs.Open "select * from T_user", conn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Load()
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\hb\桌面\db1.mdb;Persist Security Info=False"
conn.CursorLocation = adUseClient '游标放在客户端
rs.CursorLocation = adUseClient
rs.Open "select * from T_user", conn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs.Close '释放
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
2013-07-06
展开全部
按连接左边的三角键号就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询