밑에서 제가 답변한 내용인데요.
참조하세요.
Dim aconn As ADODB.Connection
Dim ars As ADODB.Recordset
‘>>> 1. DB 연결
Set aconn = New ADODB.Connection
aconn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.3.51;Data source=” & App.Path & “\MainDB.mdb”
aconn.Open
‘>>> 2. RecordSet 설정
Set ars = New ADODB.Recordset
ars.CursorLocation = adUseClient
ars.CursorType = adOpenKeyset
ars.LockType = adLockOptimistic
Dim sqlGrid As String
‘>>> 3. 쿼리문 생성
sqlGrid = “select ID,시작날짜,시작시간,종료날짜,종료시간 from 접속자관리”
‘>>> 4. 쿼리 실행
ars.Open sqlGrid, aconn
‘>>> 5. Grid 컬럼 헤드 출력
MSFlexGrid1.TextMatrix(0, 0) = “ID”
MSFlexGrid1.TextMatrix(0, 1) = “시작날짜”
MSFlexGrid1.TextMatrix(0, 2) = “시작시간”
MSFlexGrid1.TextMatrix(0, 3) = “종료날짜”
MSFlexGrid1.TextMatrix(0, 4) = “종료시간”
‘>> 6. RecordSet 결과값 Grid 출력
If ars.RecordCount > 0 Then
ars.MoveFirst
For i = 1 To ars.RecordCount
MSFlexGrid1.TextMatrix(i, 0) = ars!ID
MSFlexGrid1.TextMatrix(i, 1) = ars!시작날짜
MSFlexGrid1.TextMatrix(i, 2) = ars!시작시간
MSFlexGrid1.TextMatrix(i, 3) = IIf(IsNull(ars!종료날짜), “”, ars!종료날짜)
MSFlexGrid1.TextMatrix(i, 4) = IIf(IsNull(ars!종료시간), “”, ars!종료시간)
ars.MoveNext
Next i
End If
‘>>> 7. 닫기
ars.close
aconn.close
간단 샘플이었습니다.
자료실이나 질문&답변 검색 하시면 많이 나올겁니다. |
Comments