Re: [VB6 ] 請問VB要用ADO將資料show在datagrid要꘠…
在設計模式中指定:
DataGrid 屬性頁中(滑鼠右鍵-屬性),資料行那裡設定要顯示的欄位
或者在執行階段中指定:
Dim i As Integer, c As Integer
c = dg.Columns.Count - 1
For i = 0 To rs.Fields.Count - 1
If i > c Then c = c + 1: dg.Columns.Add c
dg.Columns(i).DataField = rs.Fields(i).Name
dg.Columns(i).Caption = rs.Fields(i).Name
Next
For i = i + 1 To c
dg.Columns.Remove i
Next
Set dg.DataSource = rs
※ 引述《Visualgirl (可愛女人)》之銘言:
: 我有個form上面有一個command按鈕和datagrid
: 我要寫一個
: 如果我按command則datagrid會show所有學生資料
: 要如何寫?
: 我的程式如下:
: Dim conn As New ADODB.Connection
: Dim rs As New ADODB.Recordset
: Private Sub Form_Load()
: Dim Connstr As String
: Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;
: Persist Security Info=False;Data Source=D:\temp\school.mdb";
: conn.Open Connstr
: rs.CursorLocation = adUseServer
: End Sub
: Private Sub Command1_Click()
: SQL = "Select * From b_student"
: rs.Open SQL, conn, adOpenKeyset, adLockOptimistic
: Set DataGrid1.DataSource = rs
: XXXXXXXXXXXXXXXXXXXXX
: End Sub
: 我將rs都set給datagrid1,但datagrid1要如何show出資料??
: XXXX的部份要如何寫??
--
▃▅▇▆▄ ▆▂▃ `
逝去感情如何能留住,半點癡情遺留殊不易,██▅▇▄▃ ▇▃▂" .
█████████▃i ▁▄▇
更多悽悽慘慘的遭遇…………██▆▃ █▅▆▃ˍ▄*
◢ ▂█▄▇▅▂▌.
我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.194.68.49
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章
33
68