Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ช่วยหน่อยดูครับ พอดีปัญหาการ Import File Excel เข้าสู่ MS SQL



 

ช่วยหน่อยดูครับ พอดีปัญหาการ Import File Excel เข้าสู่ MS SQL

 



Topic : 058604



โพสกระทู้ ( 28 )
บทความ ( 0 )



สถานะออฟไลน์




จากโค้ด

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
//*** Get Document Path ***//
$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp
$OpenFile = "MyXls/MyExcelDB.xls";
//*** Create Exce.Application ***//
$xlApp = new COM("Excel.Application");
$xlBook = $xlApp->Workbooks->Open($strPath."/".$OpenFile);
//$xlBook = $xlApp->Workbooks->Open(realpath($OpenFile));

$xlSheet1 = $xlBook->Worksheets(1);

//*** Insert to MySQL Database ***//
$objConnect = mysql_connect("localhost","root","root") or die(mysql_error());
$objDB = mssql_select_db("mydatabase");

$i=2;
while($xlSheet1->Cells->Item($i,1) != "")
{
$strSQL = "";
$strSQL .= "INSERT INTO customer ";
$strSQL .= "(CustomerID,Name,Email,CountryCode,Budget,Used,Importtime) ";
$strSQL .= "VALUES ";
$strSQL .= "('".$xlSheet1->Cells->Item($i,1)."','".$xlSheet1->Cells->Item($i,2)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,3)."','".$xlSheet1->Cells->Item($i,4)."' ";
$strSQL .= ",'".$xlSheet1->Cells->Item($i,5)."','".$xlSheet1->Cells->Item($i,6)."', getdate()) ";
mssql_query($strSQL); 
$i++;
}

//*** Close MySQL ***//
@mssql_close($objConnect);

//*** Close & Quit ***//
$xlApp->Application->Quit();
$xlApp = null;
$xlBook = null;
$xlSheet1 = null;
?>
Data Import/Inserted <?=$i;?> Record(s).
</body>
</html>



ตอน Import File น้อย เรคคอร์ดก็ไม่มีปัญหาครับ แต่พอเวลา Import หลายๆเรคอร์ด ประมาณ 800 กว่าเรคคอร์ด เริ่มมีปัญหาครับ
จะเกิด Error แบบนี้เพียบเลยครับ

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Times'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Times'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 't'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'By'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Test'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The name "paper" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'Test'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The name "paper" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ',getdate()) '. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 't'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Description' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: The label 'Status' has already been declared. Label names must be unique within a query batch or stored procedure. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'and'. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ',getdate()) '. (severity 15) in C:\AppServ\www\importexcel\act_import.php on line 31

Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\importexcel\act_import.php on line 31


ต้องแก้อย่างไรบ้างครับ



Tag : PHP, Ms SQL Server 2005, Excel (Excel.Application)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-12 09:24:04 By : paepatter View : 1327 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

แปลงให้เป็น CSV ก่อนน่ะครับ แล้วค่อย Import ครับ เพระาจถสามารถทำงานได้เร็วและเยอะกว่าครับ

Go to : PHP Convert and Import CSV to MySQL Database






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-12 12:04:58 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยดูครับ พอดีปัญหาการ Import File Excel เข้าสู่ MS SQL
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่