  | 
              
	              
	                
 
  
    |   | 
   
  
    
        
        asp loop ตัวแปร ผม DB เก็บ 3 field คือ Run_ID,Prj_Year,Financial     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ผม DB เก็บ 3 field คือ Run_ID,Prj_Year,Financial 
ตัวอย่างข้อมูล 
1,2552,10000 
2,2553,20000 
3,2555,35000 
4,2554,20000 
5,2555,50000 
 
ต้องการให้วน loop เก็บค่าใส่ในตัวแปร ควรใช้วิธีไหนดีครับ 
เช่นตัวแปรชื่อ Prj_Year1เก็บค่า 2552 ครับ Prj_Year2 เก็บ 2553  
ช่วยแนะนำหน่อยครับ ลองเขียนแล้ว Error  "Prj_Year&i=Rs("Prj_Year")" 
ใช้ array ไม่เป็นครับ 
for i = 1 to 5 
Set Rs=Server.Createobject("adodb.Recordset") 
sql="Select * From ProjectType where Run_ID='"& i &"'" 
						Rs.Open sql,con,1,3 
						Do while not rs.eof 
							Prj_Year&i=Rs("Prj_Year") 
							Financial&i=Rs("Financial") 
						Rs.movenext 
						Loop				 
						Rs.close 
						set Rs=nothing	 
next
 
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2009-12-03 08:36:29 | 
                      By :
                          mineryclub | 
                      View :
                          1527 | 
                      Reply :
                          3 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ใช้เก็บลงตัวแปร GetRows ง่ายกว่าครับ 
 
Code (ASP) 
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & Microsoft Access Tutorial</title>
</head>
<body>
<%
Dim Conn,strSQL,objRec,arrData,i
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM customer "
Set objRec = Conn.Execute(strSQL)
arrData = objRec.GetRows()
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing	
'*** arrData(Field,Rows) ***'
%>
<table width="600" border="1">
  <tr>
    <th width="91"> <div align="center">CustomerID </div></th>
    <th width="98"> <div align="center">Name </div></th>
    <th width="198"> <div align="center">Email </div></th>
    <th width="97"> <div align="center">CountryCode </div></th>
    <th width="59"> <div align="center">Budget </div></th>
    <th width="71"> <div align="center">Used </div></th>
  </tr>
<%
	For i = 0 To Ubound(arrData,2)
%>
	  <tr>
		<td><div align="center"><%=arrData(0,i)%></div></td>
		<td><%=arrData(1,i)%></td>
		<td><%=arrData(2,i)%></td>
		<td><div align="center"><%=arrData(3,i)%></div></td>
		<td align="right"><%=arrData(4,i)%></td>
		<td align="right"><%=arrData(5,i)%></td>
	  </tr>
<%
	Next
%>
</table>
<%
	
%>
</body>
</html>
 
 
Ref : ADO GetRows - Properties                        
               
               | 
             
            
              
			  			  
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-12-03 09:00:37 | 
                        By :
                            webmaster | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ถ้าไม่ได้เอาค่าไปใช้ต่อคำนวนอะรัย ก็ใช้ Rs("Prj_Year") เลยก็ได้นิครับ :)                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-12-03 10:09:53 | 
                        By :
                            Sek-Artdrinker | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 คือว่าต้องการให้ได้ตัวแปร มีชื่อว่า "Prj_Year1" โดย 1 มาจากการวน loop ครับ เพราะตัวแปรสามารถเพิ่มลบได้ ตาม dropdown ครับ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-12-03 17:41:21 | 
                        By :
                            mineryclub | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |