VB6.0如何在DATAGRID控件中显示数据库内容啊?
2个回答
2013-09-10
展开全部
这是我做的一个示例,希望对你有所帮助!!Private conn As ADODB.Connection
Private rsmc As ADODB.RecordsetPrivate Sub Command1_Click()End SubPrivate Sub Command2_Click()
On Error Resume Next
i = MsgBox("是否清空所有历史记录?", vbYesNo + vbInformation, "提示")
If i = vbYes Then
rsmc.MoveFirst
While Not rsmc.EOF
rsmc.Delete
rsmc.MoveNext
Wend
End If
End SubPrivate Sub Command3_Click()
Me.Hide
End SubPrivate Sub Form_Activate()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xs.mdb"
conn.Open
Set rsmc = New ADODB.Recordset
rsmc.CursorLocation = adUseClient
rsmc.Open "xtZZ", conn, 2, 2
Set DataGrid1.DataSource = rsmc
DataGrid1.Refresh
End Sub
Private rsmc As ADODB.RecordsetPrivate Sub Command1_Click()End SubPrivate Sub Command2_Click()
On Error Resume Next
i = MsgBox("是否清空所有历史记录?", vbYesNo + vbInformation, "提示")
If i = vbYes Then
rsmc.MoveFirst
While Not rsmc.EOF
rsmc.Delete
rsmc.MoveNext
Wend
End If
End SubPrivate Sub Command3_Click()
Me.Hide
End SubPrivate Sub Form_Activate()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\xs.mdb"
conn.Open
Set rsmc = New ADODB.Recordset
rsmc.CursorLocation = adUseClient
rsmc.Open "xtZZ", conn, 2, 2
Set DataGrid1.DataSource = rsmc
DataGrid1.Refresh
End Sub
2013-09-10
展开全部
先把DATAGRID控件与ADODC控件进行绑定,然后只要ADO控件能连上数据库打开数据库表就行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |