我有一个mysql数据库和一个gridview。现在我想计算我的插入和更新。有人建议设置一个变量来表示每个元素,例如 nUpdates 和 nInserts,但我不确定如何做到这一点?这是我正在使用的代码
For i = 0 To DataGridView1.RowCount - 1
Using dbSQL_cmd As New MySqlCommand()
student_id = DataGridView1.Item(i, 0).Value.ToString
name = DataGridView1.Item(i, 1).Value.ToString
age = DataGridView1.Item(i, 2).Value.ToString
adress = DataGridView1.Item(i, 3).Value.ToString.ToLower
dbSQL_query = "INSERT INTO student VALUES (?id, ?name, ?age, ?adress) " +
" on duplicate key update name=(name=?name, age=?age, adress=?adress)"
With dbSQL_cmd
.Parameters.AddWithValue("?id", student_id)
.Parameters.AddWithValue("?name", name)
.Parameters.AddWithValue("?age", age)
.Parameters.AddWithValue("?adress", adress)
' .Parameters.AddWithValue("?status", ?????)
.CommandText = dbSQL_query
.Connection = SQLConnection
.CommandType = CommandType.Text
End With
dbSQL_cmd.ExecuteNonQuery()
End Using
Next