我有这个代码用于上传excel文件并将数据保存到数据库中。我无法编写数据库条目的代码。 有人请帮忙
<%
if (Request("FileName") <> "") Then
Dim objUpload, lngLoop
Response.Write(server.MapPath("."))
If Request.TotalBytes > 0 Then
Set objUpload = New vbsUpload
For lngLoop = 0 to objUpload.Files.Count - 1
'If accessing this page annonymously,
'the internet guest account must have
'write permission to the path below.
objUpload.Files.Item(lngLoop).Save "D:\PrismUpdated\prism_latest\Prism\uploadxl\"
Response.Write "File Uploaded"
Next
Dim FSYSObj, folderObj, process_folder
process_folder = server.MapPath(".") & "\uploadxl"
set FSYSObj = server.CreateObject("Scripting.FileSystemObject")
set folderObj = FSYSObj.GetFolder(process_folder)
set filCollection = folderObj.Files
Dim SQLStr
SQLStr = "INSERT ALL INTO TABLENAME "
for each file in filCollection
file_name = file.name
path = folderObj & "\" & file_name
Set objExcel_chk = CreateObject("Excel.Application")
Set ws1 = objExcel_chk.Workbooks.Open(path).Sheets(1)
row_cnt = 1
'for row_cnt = 6 to 7
' if ws1.Cells(row_cnt,col_cnt).Value <> "" then
' col = col_cnt
' end if
'next
While (ws1.Cells(row_cnt, 1).Value <> "")
for col_cnt = 1 to 10
SQLStr = SQLStr & "VALUES('" & ws1.Cells(row_cnt, 1).Value & "')"
next
row_cnt = row_cnt + 1
WEnd
'objExcel_chk.Quit
objExcel_chk.Workbooks.Close()
set ws1 = nothing
objExcel_chk.Quit
Response.Write(SQLStr)
'set filobj = FSYSObj.GetFile (sub_fol_path & "\" & file_name)
'filobj.Delete
next
End if
End If
请告诉我如何将以下excel数据保存到oracle databse.any帮助将不胜感激
答案 0 :(得分:0)
您想要做的基本想法是:
逐行从电子表格中获取数据,对于每一行,对数据库执行insert
语句。如果没有您当前尝试使用的insert all
语法,您可能会过得很快。
您的SQL格式应为:
insert into <tablename> (<column_name1>, <column_name2>) values (<value1>, <value2>)
您的代码正在尝试为SQL语句生成字符串,但不会执行插入操作。您应该将其分解并输出您生成的SQL字符串以确保它是正确的。
以下是在经典ASP中插入Oracle数据库的示例:
http://home.wlv.ac.uk/~cm1958/TextVersion/OracleASP/InsertingData.html
它引用了一个getDBConnection
函数,您必须将其更改为使用数据库连接字符串的代码并创建连接对象。