我在vb.net上有一个代码,我想用vb.net的循环从mysql数据库中检索数据。
我面临的问题似乎是重复循环工作不正常,获得的数据只重复第一个数据。。
有人能帮我吗??
conn.Open()
sqlConn1 = "select * from transaksi"
data3 = New MySqlDataAdapter(sqlConn1, conn)
data3.Fill(ds3, "transaksi")
Dim keterangan As String
Dim c4 As String = String.Empty
For c As Integer = 0 To ds3.Tables("transaksi").Rows.Count - 1
sqlConn2 = "select * from transaksi"
data32 = New MySqlDataAdapter(sqlConn2, conn)
data32.Fill(ds32, "transaksi")
c4 = ds32.Tables("transaksi").Rows(c).Item("idTransaksi")
'For d As Integer = 0 To s - 1
Dim nilaihasil As Double
Dim nilaix As Double
Dim var_a As Double
Dim var_b As Double
For f As Integer = 0 To 5 - 1
sqlConn6 = "select * from transaksidetail WHERE idTransaksi = '" & c4 & "'"
data6 = New MySqlDataAdapter(sqlConn6, conn)
data6.Fill(ds6, "transaksidetail")
var_a = ds6.Tables("transaksidetail").Rows(f).Item("nilaiTransaksidetail")
sqlConn7 = "select nilai from cluster WHERE idKriteria = '" & ds6.Tables("transaksidetail").Rows(f).Item("idKriteria") & "' AND kode = 'C0'"
data7 = New MySqlDataAdapter(sqlConn7, conn)
data7.Fill(ds7, "cluster")
var_b = ds7.Tables("cluster").Rows(f).Item("nilai")
'MessageBox.Show(var_a & var_b)
nilaix += ((var_a ^ 2) - (var_b ^ 2))
Next
nilaihasil = Math.Sqrt(nilaix)
perintah.CommandType = CommandType.Text
perintah.CommandText = "INSERT INTO tempcluster (idTemp,idTransaksi,nilai,cluster) VALUES ('','" & c4 & "','" & nilaihasil & "','C0')"
perintah.Connection = conn
perintah.ExecuteNonQuery()
Next c
conn.Close()
1条答案
按热度按时间ajsxfq5m1#
我认为您的问题可能是在循环中重新填充数据表transaksi。注解和解释一致。