发布于 2007-04-11 12:35:20
0楼
Sub push_plan_display
Dim gocn, gorsAuthors, gorsAuthorsChange, gorsTitles, gorsTitlesAuthors
Dim oItem
Set gocn = CreateObject("ADODB.Connection")
Set gorsAuthors= CreateObject("ADODB.Recordset")
'CONNECT TO MSACCESS DB
'cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\WinCC V6 Workshop 0203\V6_demo3\Media\WinCCFac.mdb;Persist Security Info=False"
'CONNECT TO SQLSERVER, PUBS DB
gocn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;uid=sa;PWD=;Initial Catalog=pubs;Data Source=.\WinCC"
'gocn.open "DSN=rwer"
gorsAuthors.open "SELECT au_id, au_fname, au_lname,contract FROM Authors ORDER BY au_lname", gocn, 1, 3
Dim ListView1
Set ListView1=ScreenItems("ListView1")
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add,,CStr(gorsAuthors.Fields(0).Name),100
ListView1.ColumnHeaders.Add,,CStr(gorsAuthors.Fields(1).Name),100
ListView1.ColumnHeaders.Add,,CStr(gorsAuthors.Fields(2).Name),100
ListView1.ColumnHeaders.Add,,CStr(gorsAuthors.Fields(3).Name),100
Do While gorsAuthors.EOF=False
Set oItem=ListView1.ListItems.Add()
oItem.Text=CStr(gorsAuthors.Fields(0).Value)
oItem.subItems(1)=CStr(gorsAuthors.Fields(1).Value)
oItem.subItems(2)=CStr(gorsAuthors.Fields(2).Value)
oItem.subItems(3)=CStr(gorsAuthors.Fields(3).Value)
'ListView1.ListItems.Add,," "&gorsAuthors.Fields("au_id")&" "&gorsAuthors.Fields("au_fname")
gorsAuthors.MoveNext
Loop
gorsAuthors.close
Set gocn=nothing
End Sub
上面的过程 就是一个 用ListView控件显示读取数据库中内容的代码。
如果想读取access 的 把 连接字符串参照着改一下就可以了。
在画面中添加个listview控件,并命名为ListView1,改变控件显示的属性为列表,之后在用insert插入4个行,宽度不用定义。
以上代码只要在按钮动作中调用即可!代码肯定是可以实现该功能的 !
o! why? thinking...