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
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);
VB.Net does not have an increment operator.
Add this Function
Function GetIncrementValue(ByRef x as Integer) as Integer
x=x+1
Return x
End function
Your Code will be......
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(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "', '" + _
list.Item(GetIncrementValue(i)) + "')")
Next
Enjoy....
精彩评论