DBGrid控件的设置和使用是怎样的?
我在窗体添加了DBGrid控件,并将DataSource属性设置为“Data”
代码如下:希望实现排列相关z(i)字段=“银行存款”信息所有记录到DBGrid控件里!
执行后却显示:变量未定义!
黄条指在:“Private Sub Command1_Click()”
蓝条指在:“Set DataGrid.DataSource = Rst”
代码如下:
Option Explicit
Private Conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Private Sub Command1_Click()
Dim ii, ss, jj As Integer
Dim mysql As String
For jj = 1 To 9
mysql = "Select [j(" & jj & ")] from fl2 where [z(" & jj & ")]='银行存款' "
Set Rst = Conn.Execute(mysql)
ss = Rst.Fields.Count
If Rst.BOF = True Then
MsgBox "no!"
Else
Set DataGrid.DataSource = Rst
For ii = 0 To ss - 1
DataGrid.Columns(ii).Alignment = dbgCenter
DataGrid.Columns(ii).Width = 1000
Next ii
DataGrid.AllowUpdate = False
End Sub
Private Sub Form_Load()
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"
Set Conn = CreateObject("ADODB.Connection")
With Conn
.ConnectionString = ConString
.Open
End With
Rst.CursorLocation = adUseClient
Rst.Open "Select * From fl2", Conn, adOpenKeyset, adLockPessimistic, adCmdText
End Sub