Reputation: 1105
I'm trying to add an index to string.format
string, for example:
For i = 1 To Dataset.Tables(0).Columns.Count - 1
query_builder.Append(String.Format("@parameter{i}", i))
Next
What I'm trying to achieve is get in a similar result:
@parameter1
@parameter2
@parameter3 etc....
But I get this error:
Input string format not correct
why?
Upvotes: 0
Views: 107
Reputation: 13248
query_builder.Append(String.Format("@parameter{i}", i))
Should be
query_builder.Append(String.Format("@parameter{0}", i))
or
query_builder.AppendFormat("@parameter{0}", i)
Upvotes: 3
Reputation: 17875
You must specify a numeric value between brackets:
For i = 1 To Dataset.Tables(0).Columns.Count - 1
query_builder.Append(String.Format("@parameter{0}", i))
Next
{0}
corresponds to the item at index 0 (first item) in the list of parameters to String.Format
, which is variable i
in your case.
Upvotes: 1