我的表单上有一个DataGrid,可以正常工作..我想摆脱DataGrid并使用DataList,我该怎么做。我用来填充DataGrid的代码如下:
Private Sub Form_Load()
cn.CursorLocation = adUseClient
cn.Open "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=testitem;User=root;Password=mysql;Option=3;
End Sub"
Private Sub Command1_Click()
rs.Open "select * from item where itemname = '" & Text9.Text & "'", cn, adOpenDynamic, adLockOptimistic
Set DataList1.RowSource = rs
DataList1.DataField = itemno
Set DataGrid3.DataSource = rs
End Sub
数据网格填充得很好,但是数据主义者总是空的
我在这里缺少什么? 请帮忙。
答案 0 :(得分:0)
请尝试以下代码段(未经测试):
Private Sub Command1_Click()
rs.Open "select * from item where itemname = '" & Text9.Text & "'", cn, adOpenDynamic, adLockOptimistic
Set DataGrid3.DataSource = rs
'//Set DataList1.RowSource = rs
'//DataList1.DataField = itemno
With rs
Do While Not rs.eof
Me.ListBox1.AddItem rs!itemno
.MoveNext
Loop
.Close
End With
End Sub
或
Private Sub Command1_Click()
rs.Open "select * from item where itemname = '" & Text9.Text & "'", cn, adOpenDynamic, adLockOptimistic
Set DataGrid3.DataSource = rs
Set DataList1.RowSource = rs
DataList1.ListField = "itemno"
End Sub