progressbar提供了一个庞大的insert-update查询列表

5jvtdoz2  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(276)

解决了我只是在搜索vb.net,但我试图搜索c#,我找到了一个解决方案,只是转换到vb.net
对不起,谢谢大家!
我将插入&更新大约600个查询包含update和insert,因此我希望有一个progressbar来显示这是我将使用的查询的exp所需的时间:

Dim sqlTexts = {
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value1` = `stat_value1` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type1 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value2` = `stat_value2` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type2 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value3` = `stat_value3` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type3 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value4` = `stat_value4` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type4 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value5` = `stat_value5` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type5 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value6` = `stat_value6` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type6 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value7` = `stat_value7` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type7 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value8` = `stat_value8` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type8 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value9` = `stat_value9` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type9 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " SET `stat_value10` = `stat_value10` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type10 = 7;"
}

        Using _
            conn As New MySqlConnection("server=" & Form2.hostname.Text & ";Port=" & Form2.portid.Text & "; user id=" & Form2.hostuser.Text & "; password=" & Form2.ascentpass.Text & ";SslMode = none; database=" & Form2.databasename.Text & ""),
            command As New MySqlCommand With {
                .CommandType = CommandType.Text,
                .Connection = conn
            }
            conn.Open()
        For Each sql As String In sqlTexts
            Try
                ProgressBar1.Maximum = sql.Count
                For i As Integer = 0 To sql.Count - 1
                    command.CommandText = sql
                    command.ExecuteNonQuery()
                    If True Then
                        ProgressBar1.Value = i + 1
                    End If
                Next
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        Next
    End Using
23c0lvtd

23c0lvtd1#

之后,可以为每个循环增加一个变量 command.ExecuteNonQuery() 在查询数处设置progressbar的最大值

Dim sqlTexts = {
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value1` = `stat_value1` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type1 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value2` = `stat_value2` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type2 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value3` = `stat_value3` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type3 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value4` = `stat_value4` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type4 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value5` = `stat_value5` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type5 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value6` = `stat_value6` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type6 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value7` = `stat_value7` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type7 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value8` = `stat_value8` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type8 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " Set `stat_value9` = `stat_value9` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type9 = 7;",
"UPDATE " & Form3.WorkTableName.Text & " SET `stat_value10` = `stat_value10` " & USEMULTIPLE.Text & " " & Stamina.Text & " WHERE stat_type10 = 7;"
}

 Dim ProgressBar1 As ProgressBar
 ProgressBar1.Location = New Point(10, 10)  
 ProgressBar1.Maximum = "getNumOfQuery()"

    Using _
    conn As New MySqlConnection("server=" & Form2.hostname.Text & ";Port=" & Form2.portid.Text & "; user id=" & Form2.hostuser.Text & "; password=" & Form2.ascentpass.Text & ";SslMode = none; database=" & Form2.databasename.Text & ""),
                command As New MySqlCommand With {
                    .CommandType = CommandType.Text,
                    .Connection = conn
                }
                conn.Open()
                For Each sql As String In sqlTexts
                    Try

                        command.CommandText = sql
                        command.ExecuteNonQuery()
                        ProgressBar1.Value=ProgressBar1.Value+1
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                Next
            End Using

相关问题