  | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ทำได้หลายวิธีครับ เช่น 
1. ก็ใช้ For Loop ใน Store 
2. เขียน Function ที่ return เป็น Table ของวันที่ ที่เป็นวัน พุธ พฤหัศ ศุกร์ จากช่วงที่กำหนด แล้วนำ ไป Join เพื่อทำการ Insert ครับ 
3. ใช้ SQL Server 2008 ครับ เนื่องจาก SQL Server 2008 สามารถที่จะ Insert หลาย Record ได้ภายในหนึ่งคำสั่ง Insert ครับ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2010-01-05 00:52:11 | 
                        By :
                            tempsavedata | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 แล้วถ้าเป็น MySQL ละครับ 
สนใจหลักการFor Loopครับ 
ช่วยอธิบายได้มั๊ยครับผม 
 
เพิ่มเติมว่ามี table job 
มีfield 
- job id 
- job name 
- job date 
- job time 
 
ถ้าเกิดเพิ่มแค่ 1 row ก็จะได้แค่ 1 วัน(ไม่พุธก็พฤหัสก็ศุกร์) ถูกมั๊ยครับ 
แล้วถ้าเกิดต้องการเพิ่มทีละ 3 row จะต้องcoding ยังไงครับผม 
 
ขอบคุณมากครับ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2010-01-05 01:16:46 | 
                        By :
                            จขกท | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 หุหุ ถามหา store procedure ของ MySQL ไปเลยงั้น ทำ store เสร็จเรียกใช้ ระบุวันไป วิ่ง insert ครับเลย 
 
ยกตัวอย่าง (แต่มะมี code ให้ :P ) 
 
exec add_newjob(day1, day2)                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2010-01-05 19:35:01 | 
                        By :
                            salapao_codeman | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 คือผมลองcoding ได้แล้วแต่ มันเป็นการใส่ค่าครบทั้ง 1 ปี  
ทีนี้ผมต้องการให้มันinsertเฉพาะค่า ตาม Datetimepicker 1 และ 2 ครับ 
จะต้องประยุกต์ยังไงต่อครับ 
 
ขอความกรุณาจริงๆครับ 
 
Code (VB.NET) 
Imports MySql.Data.MySqlClient
Public Class e3jobinsert
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As Integer
        Dim datMonday As Date
        Dim sqlConnection As MySqlConnection
        Dim sqlInsertCommand As MySqlCommand
        Dim sqlInsertCommandString As String
        Dim sqlConnectionString As String
        sqlConnectionString = "Database=carproject;Data Source=localhost;User Id=root;Password=admin; Allow Zero Datetime=True"
        sqlConnection = New MySqlConnection(sqlConnectionString)
        For x = 0 To 51
            sqlConnection.Open()
            datMonday = DateAdd("ww", x, CDate("2010/1/11"))
            sqlInsertCommandString = "INSERT INTO contract (contract_id, job_type, company_name, vehicle_type, vehicle_amount, start_date, end_date, start_time, end_time, start_place, end_place, amount, day_use) VALUES(@contract_id, 'r' , @company_name, @vehicle_type, @vehicle_amount, @start_date, @end_date, @start_time, @end_time, @start_place, @end_place, amount,'" & datMonday & "')"
            sqlInsertCommand = New MySqlCommand(sqlInsertCommandString, sqlConnection)
            sqlInsertCommand.Parameters.AddWithValue("@contract_id", TextBox1.Text)
            sqlInsertCommand.Parameters.AddWithValue("@company_name", TextBox2.Text)
            sqlInsertCommand.Parameters.AddWithValue("@vehicle_type", TextBox3.Text)
            sqlInsertCommand.Parameters.AddWithValue("@vehicle_amount", TextBox4.Text)
            sqlInsertCommand.Parameters.AddWithValue("@start_date", DateTimePicker1.Value)
            sqlInsertCommand.Parameters.AddWithValue("@end_date", DateTimePicker2.Value)
            sqlInsertCommand.Parameters.AddWithValue("@start_time", DateTimePicker3.Value)
            sqlInsertCommand.Parameters.AddWithValue("@end_time", DateTimePicker4.Value)
            sqlInsertCommand.Parameters.AddWithValue("@start_place", TextBox7.Text)
            sqlInsertCommand.Parameters.AddWithValue("@end_place", TextBox8.Text)
            sqlInsertCommand.Parameters.AddWithValue("@amount", TextBox9.Text)
            sqlInsertCommand.ExecuteNonQuery()
            sqlConnection.Close()
        Next
        MessageBox.Show("Insert Completed", "Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
        'Loop through each week of the year
        'Start at 0 because for the first week you dont want to add any weeks
        '   For x = 0 To 51
        'Get Monday's date for the week
        '  datMonday = DateAdd("ww", x, CDate("11/01/2010")) 'Check date for UK/US
        'Build your SQL query
        ' sqlInsertCommandString = "INSERT INTO `TableName` (`DateField`) VALUES('" & datMonday & "')"
        'Now run your query to insert that day
        'Next
    End Sub
End Class
                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2010-01-08 17:44:44 | 
                        By :
                            จขกท | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     |