I am confused, I created a sample table with 3.000 rows so you can test it for your self. But the problem is that now the code is working as supposed to do. So I deleted some data to see if my empty lines are causing this issue. But it's working again. Now I need to try to add more than 3.000 lines to check again. In the meantime this is the complete code (there is no other code).
I have some issues with the software I am using to upload the data (DBeaver) so I did it from my browser (phpmyadmin) and I can't upload more data (more rows) at the moment.
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MysqlConn As MySqlConnection
Dim COMMAND As MySqlCommand
Public sconnection As New MySqlConnection
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'open the connection to mysql
If sconnection.State = ConnectionState.Closed Then
sconnection.ConnectionString = "server=sql11.freesqldatabase.com;userid=sql11508072;password=s2PWmyaDkE"
sconnection.Open()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Connect to mysql to get data
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=sql11.freesqldatabase.com;userid=sql11508072;password=s2PWmyaDkE"
Dim SDA As New MySqlDataAdapter
Dim dbdataset As New DataTable
Dim bsource As New BindingSource
'Clear datagridview before re-apply data
dbdataset.Clear()
DataGridView1.Columns.Clear()
DataGridView1.Refresh()
Try
MysqlConn.Open()
Dim query As String
query = ("select * from sql11508072.Complete ")
COMMAND = New MySqlCommand(query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbdataset)
bsource.DataSource = dbdataset
DataGridView1.DataSource = bsource
SDA.Update(dbdataset)
MysqlConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
'Add additional columns to datagridview
DataGridView1.Columns.Add("NameOfColumn", "First Calc Test")
DataGridView1.Columns.Add("NameOfColumn", "Second Calc Test")
'Do some test calculations
Try
For i As Integer = DataGridView1.RowCount - 1 - 1 To 0 Step -1
If CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 2 Then
Me.DataGridView1.Rows(i).Cells(8).Value = "High"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 1 Then
Me.DataGridView1.Rows(i).Cells(8).Value = "Medium"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 0 Then
Me.DataGridView1.Rows(i).Cells(8).Value = "Low"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) < 1 Then
Me.DataGridView1.Rows(i).Cells(8).Value = "Very Low"
End If
If CInt(Replace(DataGridView1.Rows(i).Cells(7).Value, ",", "")) - CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 2 Then
Me.DataGridView1.Rows(i).Cells(9).Value = "High"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(7).Value, ",", "")) - CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 1 Then
Me.DataGridView1.Rows(i).Cells(9).Value = "Medium"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(7).Value, ",", "")) - CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) > 0 Then
Me.DataGridView1.Rows(i).Cells(9).Value = "Low"
ElseIf CInt(Replace(DataGridView1.Rows(i).Cells(7).Value, ",", "")) - CInt(Replace(DataGridView1.Rows(i).Cells(5).Value, ",", "")) < 1 Then
Me.DataGridView1.Rows(i).Cells(9).Value = "Very Low"
End If
Next
Catch
End Try
End Sub
End Class