启动项目时,dgv上没有加载任何内容。如果有人可以教我或给我一些提示,我将不胜感激。任何帮助都将受到欢迎
我检查了数据库名称,它在哪里,这一切都很好。 我相信adodb连接很好。
此代码在模块中。
Public Function getRS(ByVal sql As String, rs As ADODB.Recordset, ByVal RO As Boolean, ByRef sErro As String) As Boolean
Dim Con As New ADODB.Connection
On Error Resume Next
Con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\test.mdb;Persist Security Info=true")
rs.Open(sql, Con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
If Err.Number = 0 Then
Return True
Else
sErro = Err.Description
Return False
End If
On Error GoTo 0
End Function
这是主要形式
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim retval As Boolean
Dim s As String = "Select * from table1"
Dim sErro As String = ""
retval = getRS(s, rs, False, sErro)
If retval Then
gridPessoa.DataSource = rs
End If
End Sub
期望获取数据,但看起来好像没有加载任何东西。