vbexcel資料庫
VB編程軟體可使用適當的數據控制項,通過編程語言和sql結構化查詢語句,能實現獲取excel數據並存儲到其它資料庫表中。
❷ VB能否用Excel作為資料庫,怎樣用
可以使用DAO,但是Excel資料庫是之允許添加、修改、瀏覽而不允許刪除行的:
Sub TestHDRConnectParameter(blnHDRParam As Boolean)
Dim dbs As Database
Dim rst As Recordset
Dim strHDRParam As String
If blnHDRParam = True Then
strHDRParam = "YES"
Else
strHDRParam = "NO"
End If
' Open the Microsoft Jet sample database.
Set dbs = OpenDatabase("C:\JetBook\Samples\Excel\Procts97.xls", _
False, False, "Excel 8.0;HDR=" & strHDRParam & ";")
' Create a Recordset object for the Microsoft Excel Procts worksheet.
Set rst = dbs.OpenRecordset("Procts$")
' Move to the last record and display the RecordCount property value.
With rst
.MoveLast
MsgBox "There are " & .RecordCount & " records in this worksheet."
.Close
End With
dbs.Close
End Sub
注意:
(1)HDR指定是否將首行作為標題行。
(2)表名字後面要加$符號。
❸ 如何利用VB和EXCEL開發資料庫
可以使用DAO,但是Excel資料庫是之允許添加、修改、瀏覽而不允許刪除行的:
Sub TestHDRConnectParameter(blnHDRParam As Boolean)
Dim dbs As Database
Dim rst As Recordset
Dim strHDRParam As String
If blnHDRParam = True Then
strHDRParam = "YES"
❹ VB讀取excel數據並插入到資料庫
Set xlApp = CreateObject("Excel.Application") '激活EXCEL應用程序
xlApp.Visible = False '隱藏EXCEL應用程序窗口
Set xlBook = xlApp.Workbooks.Open(FileManually) '打開工作簿,FileManually為一個EXCEL報表文件
Set xlSheet = xlBook.Worksheets(Trim(txtSheetNM.Text)) '設定工作表
For IRowsCount = 1 To xlSheet.UsedRange.Cells.Rows.Count
If Trim(xlSheet.Cells(IRowsCount, 1)) = "" Then
Exit For
End If
'將xlSheet.Cells(IRowsCount,列號)的數據插入資料庫中
'轉換男女可以判斷xlSheet.Cells(IRowsCount,列號)="男",則=1,否則=0,然後再寫入資料庫
Next IRowsCount
❺ VB打開Excel資料庫的問題
rs.Source = "select * from [Sheet1$]" 改成下面那句就可以了.
rs.Source = "select * from [Sheet1$] untion select * from [Sheet1$]"
❻ 使用VB來封裝能調用Excel來進行建立個簡單資料庫么
可以,如果不復雜用xml,稍復雜用ACCESS更好。。
❼ 用vb將Excel中的數據寫入資料庫
Private Sub Command1_Click()
Dim fileadd As String
CommonDialog1.ShowOpen
CommonDialog1.Filter = "xls文件(*.xls)|*.xls" '選擇你要的文件
fileadd = CommonDialog1.FileName
If fileadd = "" Then Exit Sub
Set xlApp = CreateObject("Excel.Application") '創建EXCEL對象
Set xlBook = xlApp.Workbooks.Open(fileadd) '打開已經存在的EXCEL工件簿文件
xlApp.Visible = False ' = True '設置EXCEL對象可見(或不可見)
Set xlSheet = xlBook.Worksheets(1) '設置活動工作表
For R = 1 To 99999 '行循環
If LTrim(RTrim(xlBook.Worksheets(1).Cells(R, 1))) <> "" Then
Call Dosql("INSERT INTO CB_JiXieFeiYong (danwei_name) VALUES (" & LTrim(RTrim(xlBook.Worksheets(1).Cells(R, 1))) & ")")
Else
R = 99999 + 1
End If
Next R
xlApp.DisplayAlerts = False '不進行安全提示 '
Set xlSheet = Nothing '
Set xlBook = Nothing '
xlApp.Quit '
Set xlApp = Nothing
Unload Me
End Sub
Private Sub Dosql(ByVal tn As String) '執行SQL語句
Dim sql As String
Set conn = New ADODB.Connection
conn.ConnectionString = condstr
conn.Open
conn.Execute tn
conn.Close
End Sub
這段代碼估計對你有用。
❽ vb excel導入資料庫怎麼做
VB存資料庫的做過,EXCEL的沒試過,應該都差不多吧,我當時也是網上找的資料學的,你也可以查一下相關資料,有時候語句都是寫的成熟的,只要替換資料庫名就可以了。
另外對於你的這個存儲過程,我建議你分開來做,先做全部存儲。全部存儲功能實現了再做數據比對及不導入操作,最後再實現提示重復訂單功能。因為個人感覺這三個東西每一個處理起來都需要時間來測試的,分開來把問題簡單化容易成功一些。
❾ vb,連接EXCEl資料庫
Sub ReadExcel()'讀取Excel文件內容
Dim x As Integer
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim AppExcel As New Excel.Application
Set AppExcel = CreateObject("Excel.Application")'創建Excel對象
Set xlBook = AppExcel.Workbooks.Open("D:\數據表.xls") '打開工作簿
If AppExcel Is Nothing Then Exit Sub'錯誤則退出
For x = 1 To AppExcel.Sheets.Count '找到對應的工作表
If AppExcel.Sheets(x).Name ="工作表名" Then
Set xlSheet = AppExcel.Sheets(x)
Exit For
End if
Next
'下面為單元格的定義
xlSheet.Cells([RowIndex],[ColumnIndex]).Value'單元格(行 , 列)
xlSheet.Range("B2:B2").Value'單元格選擇
Set xlSheet = Nothing
Set xlBook = Nothing
Set AppExcel = Nothing
End Sub
'VB6.0必需先引用Microsoft Excel 11.0 Object Library
❿ 用VB做怎麼將Excel數據導入SQL資料庫中
用VB做,將Excel數據導入SQL資料庫中:
法一:可以試著用VB書寫一段調用SQL Server資料庫DTS的代碼,然後就可以像直接使用DTS進行數據導入一樣就行Excel與SQL Server數據之間的遷移了。
方法二:可以用VB來 作EXCEL,然後一條數據一條數據的 入到資料庫中,這種方法不 使用,因為VB 作EXCEL是非常慢的,如果數據量太大,很有可能會造成宕機。