0

我想根据控制号的输入自动添加参数。

下面的代码会给我 sp_INSERT @COL5,sp_INSERT @COL4,等等......

control = 5;

while(1<=control)
column = '@COL'
string setValues = "sp_INSERT'" + column + control + "';"

control = control - 1;

我想要实现的是 sp_INSERT @COL5、@COL4、@COL3 等等……

4

2 回答 2

0

只是……循环?

int control = 5;
string colPrefix = "@COL";
var sql = new StringBuilder("sp_INSERT ").Append(colPrefix).Append(control);
// note first item has different format due to comma
for(int i = control - 1; i > 0; i--)
{
    sql.Append(", ").Append(colPrefix).Append(i);
}
sql.Append(';');
string s = sql.ToString();
于 2013-11-15T09:57:10.030 回答
0

简单的循环,不是一个完整的解决方案,但它可能会有所帮助......

string myString = "INSERT ";
for (int i = 5; i > 0; i--)
    myString = string.Format("{0} @COL{1}, ", myString, i);
于 2013-11-15T09:59:59.527 回答