解决了我只是在搜索VB.NET,但我尝试搜索C#并找到了解决方案,然后将其转换为VB.NET
对不起,谢谢大家!
我要对INSERT&UPDATE进行大约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
答案 0 :(得分:0)
您可以在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