我的桌子上有诸如键,英语短语和其他40种语言的短语。请参见下图:
我使用以下代码进行了此操作:
Sub InsertIntoMasterPhrases()
Dim objRecordsetMaster As ADODB.Recordset
Set objRecordsetMaster = New ADODB.Recordset
Dim objRecordset As ADODB.Recordset
Set objRecordset = New ADODB.Recordset
objRecordsetMaster.ActiveConnection = CurrentProject.Connection
objRecordset.ActiveConnection = CurrentProject.Connection
objRecordsetMaster.Open ("SELECT [Master Table].* FROM [Master Table];")
While objRecordsetMaster.EOF = False
objRecordset.Open ("Select [SAP_LANGUAGE to LANG].[LANGUAGE NAME], [SAP_LANGUAGE to LANG].[LANGUAGE] " & _
"From [SAP_LANGUAGE to LANG]")
While objRecordset.EOF = False
key = objRecordsetMaster.Fields("Key").Value
englishPhrase = objRecordsetMaster.Fields("English Phrase").Value
language = objRecordset.Fields("LANGUAGE").Value
translation = objRecordsetMaster.Fields(languageName).Value
If (GetRecordsExist(CStr(key), CStr(englishPhrase), CStr(language)) = "") Then
Query = "INSERT INTO [Language Sample](Key,English,Translation,Language)VALUES ('" & key & "','" & englishPhrase & "','" & translation & "','" & language & "');"
CurrentDb.Execute Query
End If
objRecordset.MoveNext
Wend
objRecordset.Close
objRecordsetMaster.MoveNext
Wend
objRecordsetMaster.Close
End Sub
//Checking records already exist in table
Function GetRecordsExist(key As String, english As String, language As String) As String
Dim db As Database
Dim Lrs As DAO.Recordset
Dim LGST As String
Set db = CurrentDb()
Set Lrs = db.OpenRecordset("SELECT KEY FROM [Language Sample] where KEY='" & key & "' and English='" & english & "' and Language = '" & language & "'")
If Lrs.EOF = False Then
LGST = "Found"
Else
LGST = ""
End If
Lrs.Close
Set Lrs = Nothing
GetRecordsExist = LGST
End Function
在主表中,我有15000条记录,当它打破15000条记录时,它变成15000 * 40 =600000。以上代码每分钟插入近10000条记录,数小时后挂断。但它也不会产生任何错误,那么我必须重新启动访问。请帮助我如何更好地进行操作。
答案 0 :(得分:0)
替代1:
使用大型UNION查询通过一条SQL语句附加许多记录,如下所述:
How to simulate UNPIVOT in Access 2010?
您可能希望将其拆分为几个块(例如一次5或10种语言),否则Access可能会阻塞查询。
替代2:
不要为每个记录运行INSERT语句,而应将DAO记录集与class ChatBotCheckList: UIView {
var tableView: UITableView = {
let tableView = UITableView()
tableView.register(ChatBotCheckListCell.self, forCellReuseIdentifier: "MyCell")
tableView.translatesAutoresizingMaskIntoConstraints = false
return tableView
}()
let doneButton: FilledButton = {
let doneButton = FilledButton(backgroundColor: .fittoOnboardingGradientStart, textColor: .white, cornerRadius: 5.0, shadowColor: .fittoOnboardingGradientEnd)
doneButton.translatesAutoresizingMaskIntoConstraints = false
doneButton.titleLabel?.font = .boldSystemFont(ofSize: 17.0)
doneButton.setTitle("Done", for: .normal)
return doneButton
}()
let stackView: UIStackView = {
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.alignment = .fill
stackView.distribution = .fillEqually
stackView.spacing = 10.0
return stackView
}()
var answers = [ChatBotAnswer]() {
didSet {
setupStackView()
tableView.reloadData()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
// MARK: Lifecycle
override func layoutSubviews() {
super.layoutSubviews()
}
}
// MARK: - Setup UI
extension ChatBotCheckList {
fileprivate func setupUI() {
addSubview(stackView)
let topAnchorPadding: CGFloat = answers.count <= 2 ? 50.0 : 0
stackView.anchor(top: topAnchor, leading: leadingAnchor, bottom: bottomAnchor, trailing: trailingAnchor, padding: UIEdgeInsets(top: topAnchorPadding, left: 28.0, bottom: 0, right: 28.0), size: .zero)
}
private func setupDoneButton() {
doneButton.alpha = 0
//doneButton.addTarget(self, action: #selector(doneButtonTapped(_:)), for: .touchUpInside)
}
private func setupStackView() {
addSubview(stackView)
stackView.anchor(top: topAnchor, leading: leadingAnchor, bottom: bottomAnchor, trailing: trailingAnchor, padding: UIEdgeInsets(top: 90.0, left: 28.0, bottom: 20.0, right: 28.0))
stackView.addArrangedSubview(tableView)
stackView.addArrangedSubview(doneButton)
setupUI()
}
}
// MARK: - Setup Table View
extension ChatBotCheckList: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return answers.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
cell.textLabel!.text = "\(answers[indexPath.row].message)"
return cell
}
}
一起使用。这在幅度上更快,请参见以下答案:
https://stackoverflow.com/a/33025620/3820271