当前位置:首页 » 操作系统 » 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

热点内容
安卓如何听m4a 发布:2025-08-30 05:07:09 浏览:965
存储服务器到电脑怎么布线 发布:2025-08-30 05:05:42 浏览:933
安全好的密码是什么 发布:2025-08-30 05:00:25 浏览:952
华为电视盒子账号和密码是什么 发布:2025-08-30 04:46:31 浏览:103
移动卡服务器密码是什么 发布:2025-08-30 04:21:02 浏览:247
linux卷管理 发布:2025-08-30 03:58:05 浏览:212
如何查到自己的wifi密码 发布:2025-08-30 03:49:05 浏览:662
linux默认编码 发布:2025-08-30 03:44:23 浏览:289
如何取消安卓手机日志抓取文件 发布:2025-08-30 03:20:12 浏览:539
安卓渠道服什么样子 发布:2025-08-30 03:19:21 浏览:922