  | 
              
	              
	                
 
  
    |   | 
   
  
    
        
        จากรูปนะค่ะจะเป็นการสั่งซื้อของซึ่งแล้วแต่ลูกค้าว่าจะซื้อกี่รายการ บางคน 1 ราย บางคนหลายรายการ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                จากรูปนะค่ะจะเป็นการสั่งซื้อของซึ่งแล้วแต่ลูกค้าว่าจะซื้อกี่รายการ บางคน 1 ราย บางคนหลายรายการ 
มีปัญหาเรื่องหน้า save ค่ะ เวลาsaveข้อมูลลูกค้าที่ซื้อรายการเดียวข้อมูลของแถวอื่นที่ไม่ได้กรอกจะบันทึกลงฐานข้อมูลของเราด้วย 
เลยลองเขียนหน้าบันทึกข้อมูลขึ้นมาแต่มัน error ดูให้หน่อยได้ไหมค่ะ หรือมีคำแนะนำอื่นไหม 
  
 
โค้ดหน้าบันทึกค่ะ 
Code (ASP) 
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & SQL Server Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "Driver={SQL Server};Server=localhost;Database=mydatabase;Uname=THAISINTO\administrator;PWD=;" 
strSQL = ""
strSQL = strSQL &"INSERT INTO QUOTATION "
strSQL = strSQL &"(quote_no,quote_date,prepare,incharge,currency,customer_ID,add_ID,cust_contact,cust_tel,cust_fax,quote_title,refmodel,model,proj_code_main,rev,remark,delivery2,delivery,payterm,proj_code_sub) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("quotation")&"','"&Request.Form("date")&"','"&Request.Form("prepare")&"','"&Request.Form("incharge")&"','"&Request.Form("Currency")&"','"&Request.Form("ddlGeo")&"','"&Request.Form("ddlProvince")&"' "
strSQL = strSQL &",'"&Request.Form("Contact")&"','"&Request.Form("Tel")&"', '"&Request.Form("Fax")&"','"&Request.Form("title")&"','"&Request.Form("refmodel")&"','"&Request.Form("model")&"','"&Request.Form("Projcodemain")&"','"&Request.Form("rev")&"','"&Request.Form("remark")&"','"&Request.Form("delivery2")&"', '"&Request.Form("delivery")&"','"&Request.Form("payterm")&"','"&Request.Form("Projcodesub")&"') "
IF Request.Form("No") = 1 Then
strSQL = strSQL &"INSERT INTO QUOTATION_DETAIL "
strSQL = strSQL &"(quote_no,no,part_name,qty,qty_unit,supplier,price,cost_baht,cost_yen,rate,unit_cost_thb,cost_total,price_total,profit,cost_ratio,pr_request,buhinkun,royalty,stm_part_no) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("quotation")&"','"&Request.Form("No")&"','"&Request.Form("Description")&"','"&Request.Form("Qty")&"','"&Request.Form("Unit")&"','"&Request.Form("Suplier")&"','"&Request.Form("Quote")&"' "
strSQL = strSQL &",'"&Request.Form("CostTHBInput")&"','"&Request.Form("CostYEN")&"', '"&Request.Form("rate")&"','"&Request.Form("CostTHBConvert")&"','"&Request.Form("CostTOTEL")&"','"&Request.Form("QuoteTOTEL")&"','"&Request.Form("Profit")&"','"&Request.Form("Ratio")&"','"&Request.Form("PR.No.")&"','"&Request.Form("Buhinkun")&"', '"&Request.Form("Royalty")&"','"&Request.Form("STMPartNo ")&"') "
Set objExec = Conn.Execute(strSQL)
End IF
IF Request.Form("No2") = 2 Then
strSQL = strSQL &"INSERT INTO QUOTATION_DETAIL "
strSQL = strSQL &"(quote_no,no,part_name,qty,qty_unit,supplier,price,cost_baht,cost_yen,rate,unit_cost_thb,cost_total,price_total,profit,cost_ratio,pr_request,buhinkun,royalty,stm_part_no) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("quotation")&"','"&Request.Form("No2")&"','"&Request.Form("Description2")&"','"&Request.Form("Qty2")&"','"&Request.Form("Unit2")&"','"&Request.Form("Suplier2")&"','"&Request.Form("Quote2")&"' "
strSQL = strSQL &",'"&Request.Form("CostTHBInput2")&"','"&Request.Form("CostYEN2")&"', '"&Request.Form("rate2")&"','"&Request.Form("CostTHBConvert2")&"','"&Request.Form("CostTOTEL2")&"','"&Request.Form("QuoteTOTEL2")&"','"&Request.Form("Profit2")&"','"&Request.Form("Ratio2")&"','"&Request.Form("PR.No.2")&"','"&Request.Form("Buhinkun2")&"', '"&Request.Form("Royalty2")&"','"&Request.Form("STMPartNo2")&"') "
Set objExec = Conn.Execute(strSQL)
Next
End IF
Set objRec = Conn.Execute(strSQL)
If Err.Number = 0 Then
     response.redirect("viewallquotation.asp")
Else
	Response.write("Error Save ["&strSQL&"] ("&Err.Description&")")
End If
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</body>
</html>
 
 
  Tag : ASP, Ms SQL Server 2005               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2011-05-11 14:28:31 | 
                      By :
                          gusjang | 
                      View :
                          1522 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ใช้ IF นี่แหละครับ ถ้า No ไม่มีค่าก็ไม่ต้อง ให้ save ครับ ว่าแต่ทำไมไม่ใช้ Loop ครับ ง่ายกว่ากันเยอะครับ 
 
Code (ASP) 
<% Option Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objExec,i
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/mydatabase.mdb"),"" , ""
For  i = 1 To Request.Form("hdnLine")
If Trim(Request.Form("txtCustomerID" & i)) <> "" Then
strSQL = ""
strSQL = strSQL &"INSERT INTO customer "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("txtCustomerID" & i)&"','"&Request.Form("txtName" & i)&"', '"&Request.Form("txtEmail" & i)&"' "
strSQL = strSQL &",'"&Request.Form("txtCountryCode" & i)&"','"&Request.Form("txtBudget" & i)&"', '"&Request.Form("txtUsed" & i)&"') "
Set objExec = Conn.Execute(strSQL)
End IF
Next
Response.write("Save completed. Click <a href='asp_access_multiple_insert3.asp'>here</a> to view.")
Conn.Close()
Set objExec = Nothing
Set Conn = Nothing
%>
</body>
</html>
 
 
 
http://www.shotdev.com/asp/asp-access/asp-access-add-insert-multiple-record/                        
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-05-11 14:43:12 | 
                        By :
                            webmaster | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |