0

这是我的 vb.net 代码的循环

Do While (Not stringReader Is Nothing)
                Application.DoEvents()
                percent = Math.Round(curline * 100.0F / lineCount)

                If (String.Compare(lineAbove, "/") = 0) Then 
                    stringReader = fileReader.ReadLine()
                    curline = curline + 1
                    currentCategory = stringReader
                    TestID = TestID + 1
                    totalTests = totalTests + 1

                Else 
                    'INSERT INTO table1
                    mySqlCommand = New SqlCeCommand("
                    INSERT INTO table1(q_text, q_mark, q_category, q_test)
                    VALUES (?, ?, ?, ?)")
                    mySqlCommand.Connection = conn

                    'These VALUES
                    words = stringReader.Split(New Char() {" "c})
                    mySqlCommand.Parameters.AddWithValue("@q_text", words(0))
                    mySqlCommand.Parameters.AddWithValue("@q_mark", words(1))
                    mySqlCommand.Parameters.AddWithValue("@q_category", currentCategory)
                    mySqlCommand.Parameters.AddWithValue("@q_test", TestID)

                    'EXECUTE SQL
                    Try
                        SQLResult = mySqlCommand.ExecuteNonQuery()
                    Catch ex As Exception
                        MsgBox(ex.Message())
                    End Try

                    lblImport.Text = "Please wait ... " & percent & "%" & "."
                    TotalQuestions = TotalQuestions + 1
                End If
                stringReader = fileReader.ReadLine()
                curline = curline + 1
                lineAbove = stringReader
            Loop

当我的代码中有超过一百万行时,这需要 10 分钟(很多)来执行。你知道我怎样才能加快处理非常大的文件的过程吗?我阅读的 .txt 文件具有相同的格式

Titlex
q1 0
q2 1
q3 1
q4 0
/
Titlexx
q1 0
q2 1
q3 1
q4 0
q5 1

在 q1,q2,...,qx 中没有任何限制,并且第二个单词始终为 0 或 1

预先感谢

4

0 回答 0