Daniel Daniel - 3 months ago 19
Vb.net Question

VB.NET Incrementing Indexes

I am having trouble incrementing the indexes of my list item properties. Here is the code.

Dim i As Integer = 0

For x As Integer = 1 To list.Count / 19
database.ExecuteCommand("INSERT INTO Contacts VALUES ('" + _
list.Item(i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "', '" + _
list.Item(++i) + "')")
Next


The ++i does not increment at all in the parameters.

Thanks

Answer

you need to use your loop variable (x) and increase the index in that manner.

I'm doing this in C# but I'm sure you will understand.

string sql = "INSERT INTO Contact VALUES ('";

for(int i = 1; i < list.Count ; i++)
{
   sql += list.Item(i) + "', '";

}
sql = sql.Remove(sql.Length -1);
sql += ")";

Database.ExecuteCommand(sql);
Comments