|  | 
	                
  
    |  |  
    | 
        
        ถ้าเราต้องการบัยทึกข้อมูลหลายๆ รายการลงในฐานข้อมูลพร้อมกันต้องทำยังไงค่ะ     |  
    |  |  
 
              
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Loop ประมาณนี้ครับ 
 Code (VB.NET)
 
 Dim row As Integer = datagridview1.rowcount
Dim money As Integer = 0
Dim i As Integer = 0
Do While (i < row)
    Dim wage As Integer = convert.toint32(datagridview1.rows(i).cells(7).value.tostring)
    Dim amount As Integer = convert.toint32(datagridview1.rows(i).cells(5).value.tostring)
    Dim price As Integer = convert.toint32(datagridview1.rows(i).cells(4).value.tostring)
    Dim discount As Integer = convert.toint32(datagridview1.rows(i).cells(6).value.tostring)
    ' Insert
    Dim sql As String = " insert into ...."
    i = (i + 1)
Loop
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-08 07:38:04 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | มัน error  The ConnectionString property has not been initialized. 
 ตรง con.Open() ค่ะ
 
 
 Code (VB.NET)
 
   Dim sqladd As String
        Dim rbTest As Integer
        Dim row As Integer = DataGridView1.RowCount
        Dim i As Integer = 0
        con = New OleDbConnection
        comm = New OleDbCommand
        If con.State = ConnectionState.Open Then con.Close()
        con.Open()
        'Query 1 '
        If RadioButton1.Checked = True Then
            rbTest = 0
        ElseIf RadioButton2.Checked = True Then
            rbTest = 1
        End If
        sqladd = "insert into pay_tax(id_pay,payment,id_tax,assessment,pay,status)"
        sqladd &= " values ('" & TextBox1.Text & "',"
        sqladd &= "'" & DateTimePicker2.Value & "',"
        sqladd &= "'" & TextBox2.Text & "',"
        sqladd &= "'" & DateTimePicker1.Value & "',"
        sqladd &= "'" & Label11.Text & "',"
        sqladd &= "'" & rbTest & "')"
        comm = New OleDbCommand
        With comm
            .CommandText = sqladd
            .CommandType = CommandType.Text
            .Connection = con
            .ExecuteNonQuery()
        End With
        'Query 2 '
        Do While (i < row)
            Dim id_la As Integer = Convert.ToInt32(DataGridView1.Rows(i).Cells(0).Value.ToString)
            Dim id_shop As Integer = Convert.ToInt32(DataGridView1.Rows(i).Cells(1).Value.ToString)
            sqladd = "insert into detail(id_pay,id_la,m_enhances,id_shop)"
            sqladd &= " values('" & TextBox1.Text & "',"
            sqladd &= "'" & id_la & "',"
            sqladd &= "'" & Label5.Text & "',"
            sqladd &= "'" & id_shop & "')"
            i = (i + 1)
        Loop
        comm = New OleDbCommand
        With comm
            .CommandText = sqladd
            .CommandType = CommandType.Text
            .Connection = con
            .ExecuteNonQuery()
        End With
        MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "ยืนยันการบันทึก")
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-08 09:15:48 | By :
                            MoMay |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (VB.NET) 
 Public Con As New SqlConnection("Data Source=ServerName;Initial Catalog=db_Name;User ID=sa;Password=xxx")
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-09 19:38:46 | By :
                            Downrung |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |