static ArrayList arl=new ArrayList();
private void button1_Click(object sender, System.EventArgs e)
{
string sql1="select * from 表1 where 条件1='名字1'";
string sql2="select * from 表2 where 条件1='地址2'";
string sql3="select * from 表3 where 条件1='性别3'";
arl.Add(sql1);
arl.Add(sql2);
arl.Add(sql3);
} private void button2_Click(object sender, System.EventArgs e)
{
for(int i=0;i<arl.Count;i++)
{
MessageBox.Show( ? );
}
}
MessageBox.Show( ? ) 这里怎么吧 arl里面的 3句 select 语句完整的读出来??
如果button1_Click()点了两次 读出来的会是 sql1 2次 sql2 2次 sql3 2次了???

解决方案 »

  1.   

    Sample code as follow:
    private string ReadQueryString( int Index )
    {
       if( Index >= 0 && Index < arl.Count )
            return arl[i].ToString();
       else
            return null;
    }private void button2_Click(object sender, System.EventArgs e)
    {
        string strQuery = ReadQueryString( yourIndex );
        if( null != strQuery )
             MessageBox.Show( strQuery );
    }
      

  2.   

    static ArrayList arl=new ArrayList();这样button1_Click()点两次 读出的肯定是两次了.
      

  3.   

    你在click里面要先把arraylist的变量清空:
    static ArrayList arl=new ArrayList();
    private void button1_Click(object sender, System.EventArgs e)
    {
                               arl.Clear();//在这里加上这句
    string sql1="select * from 表1 where 条件1='名字1'";
    string sql2="select * from 表2 where 条件1='地址2'";
    string sql3="select * from 表3 where 条件1='性别3'";
    arl.Add(sql1);
    arl.Add(sql2);
    arl.Add(sql3);
    }