dim V_column_name() As String '先把欄位名稱用陣列裝起來
strSQL = "SELECT * FROM " & 欄位名稱 & ""
DS = Query(strSQL)
DGV.DataSource = DS.Tables(0)
ReDim V_column_name(DGV.Columns.Count - 1) '
For kk = 0 To DGV.Columns.Count - 1
V_column_name(kk) = DGV.Columns(kk).HeaderText
Next
For kk = 0 To DGV.Rows.Count - 2
strSQL = "INSERT INTO " & 欄位名稱 & " ("
For II = 0 To V_column_name.Length - 1
If II = V_column_name.Length - 1 Then
strSQL = strSQL & "" & V_column_name(II) & "" & ")"
Else
strSQL = strSQL & "" & V_column_name(II) & "" & " , "
End If
Next
strSQL = strSQL & " VALUES ("
For Jj = 0 To DGV.Columns.Count - 1
If Jj = DGV.Columns.Count - 1 Then
strSQL = strSQL & "'" & DGV.Rows(kk).Cells(Jj).Value & "'" & ")"
Else
strSQL = strSQL & "'" & DGV.Rows(kk).Cells(Jj).Value & "'" & ","
End If
Next
'以上insert會因為資料表的欄位內容、資訊等等,把insert語法自動組合出來
沒有留言:
張貼留言