ASP CSV & ADO Insert Record (Driver={Microsoft Text Driver (*.txt; *.csv)}) |
ASP CSV & ADO Insert Record เป็นตัวอย่างการใช้งาน CSV ผ่าน Driver ของ Driver={Microsoft Text Driver (*.txt; *.csv)} ในการ Insert Record ให้กับไฟล์ CSV ด้วย ADO
csv/customer.csv
CustomerID,Name,Email,CountryCode,Budget,Used
"C001","Win Weerachai","[email protected]","TH","1,000,000.00","600,000.00"
"C002","John Smith","[email protected]","EN","2,000,000.00","800,000.00"
"C003","Jame Born","[email protected]","US","3,000,000.00","600,000.00"
"C004","Chalee Angel","[email protected]","US","4,000,000.00","100,000.00"
ตัวอย่าง
AspOdbcInsertCSV.asp
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & Insert CSV</title>
</head>
<body>
<%
Dim Conn,strSQL,objExec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open " Driver={Microsoft Text Driver (*.txt; *.csv)}; " & _
"Dbq=" & Server.MapPath("csv/") & ";Extensions=asc,csv,tab,txt;Persist Security Info=False"
strSQL = ""
strSQL = strSQL &"INSERT INTO customer.csv "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('C005','Mr.Weerachai Nukitram','[email protected]' "
strSQL = strSQL &",'TH','200000','100000') "
Set objExec = Conn.Execute(strSQL)
If Err.Number = 0 Then
Response.write("Save Done.")
Else
Response.write("Error Save ["&strSQL&"] ("&Err.Description&")")
End If
Conn.Close()
Set objExec = Nothing
Set Conn = Nothing
%>
</body>
</html>
Screenshot
CSV & ADO
Asp Excel บทความเกี่ยวกับการเขียน ASP กับ Microsoft Excel
|