AA1.Text一直到AA100.text循环取值怎么写?
AA1.Text一直到AA100.text循环取值怎么写?
我下面写的是错的,应该怎样修改?
for (int i = 0; i < 100; i++)
{
if ( Convert.ToInt32(AA[i].Text)!=0)
{string strupdate = "update zong set shuzhi = shuzhi+ "+Convert.ToInt32(AA[i]A.Text)+ " where xvhao= "+i;
OleDbCommand upCmd = new OleDbCommand( strupdate);
upCmd.Connection = myConn;
myConn.Open();
upCmd.ExecuteNonQuery();
}myConn.Close();
}
------解决方案--------------------keyword:FindControl
------解决方案--------------------Request.Form[ "AA " + i.ToString()]
------解决方案--------------------for (int i = 1; i <= 100; i++)
{
TextBox tb = (TextBox)this.FindControl( "AA " + i.ToString());
if (tb != null && Convert.ToInt32(tb.Text) != 0)
{
string strupdate = "update zong set shuzhi = shuzhi + " + Convert.ToInt32(tb.Text) + " where xvhao= "+i;
OleDbCommand upCmd = new OleDbCommand( strupdate);
upCmd.Connection = myConn;
myConn.Open();
upCmd.ExecuteNonQuery();
}
myConn.Close();
}
------解决方案--------------------使用string.format
string temp= " ";
int ai;
for(int i=0;i <100;i++)
{
ai = Convert.ToInt32(AA[i].Text);
temp= string.format( "update zong set shuzhi = shuzhi + {0} where xvhao= {1} ",
ai,i);
}
这个AA[i]A 不是一个数组了,用AA[i]比较好了
呵呵,关键是思路清晰了,我看你的代码页不大明白什么意图,呵呵
------解决方案--------------------for (int i = 1; i <= 100; i++)
{
TextBox tb = (TextBox)this.FindControl( "AA " + i.ToString());
if (tb != null && Convert.ToInt32(tb.Text) != 0)
myConn.Open();
{
string strupdate = "update zong set shuzhi = shuzhi + " + tb.Text + " where xvhao= " + i.ToString();
OleDbCommand upCmd = new OleDbCommand(strupdate);
upCmd.Connection = myConn;
upCmd.ExecuteNonQuery();
}
myConn.Close();
}
------解决方案--------------------string strupdate = "update zong set shuzhi = shuzhi + ' " + tb.Text + " ' where xvhao= " + i.ToString();