查询使用数组

时间:2015-06-24 07:44:30

标签: sql

我有数组列表:

Dim monthz As String() = {"jan","feb","mar","apr","may","jun","jul","aug","sept","oct", "nov", "dec"}
Dim ko3 As Double, ko1 as integer
ko3 = 0.02

这些字符串是我的表名为“mytable”的属性名称。 我想使用此查询使用ko3的增量值更新数据库:

For ko1 = 0 To 11 Step 1
    connection.connectDB()
    sql = "update tbl_coll_penalty set " & monthz(kol) & " = '" & ko3 & "' where year = '" & current_year1 & "'
    acscmd1 = New Npgsql.NpgsqlCommand(sql, pgConnection)
    acscmd1.ExecuteNonQuery()
    ko3 += 0.02       
Next ko1

我的问题是我的查询出错了,我选择了表名 帮帮我吧tnx提前。

1 个答案:

答案 0 :(得分:1)

请尝试使用此循环:(我认为您使用的是for循环'kol'中不存在的变量)

For ko1 = 0 To 11 Step 1
    connection.connectDB()
    sql = "update tbl_coll_penalty set " & monthz(ko1) & " = '" & ko3 & "' where year = '" & current_year1 & "'
    acscmd1 = New Npgsql.NpgsqlCommand(sql, pgConnection)
    acscmd1.ExecuteNonQuery()
    ko3 += 0.02       
Next ko1