當前位置:首頁 » 操作系統 » vb循環輸出資料庫資料庫資料庫數據

vb循環輸出資料庫資料庫資料庫數據

發布時間: 2025-01-04 00:49:29

㈠ VB中把SQL資料庫的數據輸出到Excel

用下面這段代碼,根據自己實際修改一下就好

Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
If Adodc1.Recordset.RecordCount > 0 Then
xlApp.Visible = True
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)).Merge
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)) = "未發料統計表"
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)).HorizontalAlignment = xlCenter
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 9)).VerticalAlignment = xlCenter

'xlSheet.Cells(1, 9) = "未發料統計表"
For i = 0 To TDBGrid1.Columns.Count - 1
xlSheet.Cells(2, i + 1) = TDBGrid1.Columns(i).Caption
Next i
Adodc1.Recordset.MoveFirst
Do Until Adodc1.Recordset.EOF
i = Adodc1.Recordset.AbsolutePosition
For j = 0 To TDBGrid1.Columns.Count - 1
xlSheet.Cells(i + 2, j + 1) = TDBGrid1.Columns(j)
Next j

Adodc1.Recordset.MoveNext
Loop
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(i + 2, j)).Borders.LineStyle = xlContinuous
End If
End Sub

㈡ VB6.0紼嬪簭:鏁版嵁搴撲腑鐨勬暟鎹鍦ㄦ枃鏈妗嗕腑寰鐜鏄劇ず,鎬庝箞瀹炵幇

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select name from 嫻嬭瘯"
Adodc1.Refresh
Timer1.Interval = 10000

End Sub

Private Sub Timer1_Timer()
Text1 = Adodc1.Recordset.Fields("name")
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst

End Sub

熱點內容
QQ密碼記不住了怎麼辦 發布:2025-07-04 12:01:40 瀏覽:112
android銀行卡支付 發布:2025-07-04 11:39:00 瀏覽:569
數控編程點孔 發布:2025-07-04 11:21:20 瀏覽:661
安卓手機信號弱如何增強 發布:2025-07-04 11:09:01 瀏覽:757
安卓什麼品牌帶陀螺儀 發布:2025-07-04 11:08:59 瀏覽:593
伺服器如何接入互聯網 發布:2025-07-04 11:01:08 瀏覽:477
網站伺服器資料庫伺服器 發布:2025-07-04 11:00:07 瀏覽:397
稀土開采需要哪些人員配置 發布:2025-07-04 10:59:57 瀏覽:465
少兒編程指引 發布:2025-07-04 10:59:05 瀏覽:623
安卓怎麼掃門禁卡 發布:2025-07-04 10:52:42 瀏覽:875