不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
VB6.0编程给DataGrid绑定数据示例
编辑:dnawo 日期:2009-09-28
①选择菜单"工程→部件",添加"Microsoft DataGrid Control 6.0 (OLEDB)",从工具箱中拖个DataGrid到窗体上;
②选择菜单"工程→引用",添加"Microsoft ActiveX Data Objects 2.6 Library",这样在代码就可以使用ADO对象了;
③添加以下代码:
运行程序,可以了^_^
②选择菜单"工程→引用",添加"Microsoft ActiveX Data Objects 2.6 Library",这样在代码就可以使用ADO对象了;
③添加以下代码:
复制内容到剪贴板 程序代码
Option Explicit
Dim objConn As ADODB.Connection
Dim objRs As ADODB.Recordset
Private Sub Form_Load()
On Error Resume Next
Set objConn = New ADODB.Connection
Set objRs = New ADODB.Recordset
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\demo3.mdb;"
objConn.Open
objRs.CursorLocation = adUseClient
objRs.Open "Select ProductId,ProductName,Discontinued FROM Products", objConn, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = objRs
If Err.Number <> 0 Then
MsgBox Err.Description
End If
On Error GoTo 0
End Sub
'释放资源
Private Sub Form_Unload(Cancel As Integer)
'不操作此步会出错:The current row is not available
If TypeName(DataGrid1.DataSource) <> "Nothing" Then
Set DataGrid1.DataSource = Nothing
End If
If TypeName(objRs) <> "Nothing" Then
objRs.Close
Set objRs = Nothing
End If
If TypeName(objConn) <> "Nothing" Then
objConn.Close
Set objConn = Nothing
End If
End Sub
Dim objConn As ADODB.Connection
Dim objRs As ADODB.Recordset
Private Sub Form_Load()
On Error Resume Next
Set objConn = New ADODB.Connection
Set objRs = New ADODB.Recordset
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\demo3.mdb;"
objConn.Open
objRs.CursorLocation = adUseClient
objRs.Open "Select ProductId,ProductName,Discontinued FROM Products", objConn, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = objRs
If Err.Number <> 0 Then
MsgBox Err.Description
End If
On Error GoTo 0
End Sub
'释放资源
Private Sub Form_Unload(Cancel As Integer)
'不操作此步会出错:The current row is not available
If TypeName(DataGrid1.DataSource) <> "Nothing" Then
Set DataGrid1.DataSource = Nothing
End If
If TypeName(objRs) <> "Nothing" Then
objRs.Close
Set objRs = Nothing
End If
If TypeName(objConn) <> "Nothing" Then
objConn.Close
Set objConn = Nothing
End If
End Sub
运行程序,可以了^_^
评论: 0 | 引用: 0 | 查看次数: 7328
发表评论
请登录后再发表评论!