gpt4 book ai didi

mysql - 用于显示大量 INSERT - UPDATE 查询的进度栏

转载 作者:行者123 更新时间:2023-11-29 16:59:24 25 4
gpt4 key购买 nike

已解决,我只是在搜索 VB.NET,但我尝试搜索 C#,找到了解决方案,然后将其转换为 VB.NET

抱歉并感谢大家!

我将插入和更新大约 600 个包含更新和插入的查询,因此我想要一个进度条来显示需要多长时间,这是我将使用的查询的 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

最佳答案

您可以在command.ExecuteNonQuery()之后为每个cicle增加一个变量,并且您必须在查询数处设置进度条的最大值

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

关于mysql - 用于显示大量 INSERT - UPDATE 查询的进度栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52380128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com