 |
|
|
 |
 |
|
Code (ASP)
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP TextStream Object</title>
</head>
<body>
<%
Dim Conn,strSQL,objExec
'*** open Connect to Access Database ***'
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
Dim objFSO, objStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.OpenTextFile(Server.MapPath("MyFiles/thaicreate.txt"))
Do Until objStream.AtEndOfStream
arrRows = Split(objStream.ReadLine," ")
strSQL = ""
strSQL = strSQL &"INSERT INTO customer2 "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&arrRows(0)&"','"&arrRows(1)&"','"&arrRows(2)&"' "
strSQL = strSQL &",'"&arrRows(3)&"','"&arrRows(4)&"','"&arrRows(5)&"') "
Set objExec = Conn.Execute(strSQL)
Set objExec = Nothing
Loop
objStream.Close
Set objStream = Nothing
Set objFSO = Nothing
%>
</body>
</html>
ตัวอย่างการ Insert ครับ
|
 |
 |
 |
 |
Date :
2011-07-07 16:45:17 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2011-07-12 09:39:13 |
By :
ueng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอรบกวนถามอีกนิดค่ะ ว่ามีฟังก์ชันนับจำนวนบรรทัดของ text file รึเปล่าค่ะหรือต้องเขียนวนลูปเอาเอง ฟังก์ชันอื่นๆ ของ ASP หาอ่านได้ที่ไหนอีกค่ะ ขอขอบคุณมากอีกครั้งค่ะ
|
 |
 |
 |
 |
Date :
2011-07-12 09:47:12 |
By :
ueng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คงจะต้องเขียนนับ Loop เอาครับ 
|
 |
 |
 |
 |
Date :
2011-07-12 11:53:58 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอความช่วยเหลือต่อค่ะเกี่ยวกับการใช้ Funtion cInt() หลังจากตัด File.txt แล้วได้ปี ค.ศ. ต้องการเปลี่ยนเป็นปี พ.ศ.
แต่พบปัญหาดังนี้ค่ะ
strYear = cInt(right(trim(arrRows(39)),4))
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'cInt'
/addwu.asp, line 99
จึงใช้ Function isNumeric() ตรวจสอบได้ค่าเป็น True จึงใช้
strDate = right(trim(arrRows(39)),4)
strDate = strDate+543)
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: ""]'
เลยลองวิธีข้างล่างนี้แล้วได้ผล
if isnumeric(str) then
add543= str +543
end if
ผลบวกถูกต้องแต่ไม่เข้าใจ อยากทราบข้อจำกัดการใช้ Function cInt() แล้วเหตุที่ทำให้เกิดผลข้างต้นค่ะ
ผู้รู้ทุกท่านช่วยชี้แนะด้วยค่ะ
|
 |
 |
 |
 |
Date :
2011-07-20 13:52:42 |
By :
ueng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|