我想把下面定义为一个函数,方便调用它,怎么定义?输入的是一个字符串,也就是相当于“this.textBox2.Text.ToString().Trim()”中的内容,返回的是字符串组的内容,相当于gf[o]中的内容,麻烦高手帮我弄一下?
         Qryzhanzhan="select Line_ID  from Busline where Stop_Name ="+"'"+this.textBox2.Text.ToString().Trim()+"'";
   Qrycnn=new SqlConnection(this.Qryzhanzhanstr);
   this.Qrycnn.Open();
   SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);  
   SqlDataReader reader=cmd.ExecuteReader();
   int o =0;
   string[] gf=new string[50]; 
   while(reader.Read()) 
   {
   gf[o]=reader["Line_ID"].ToString(); o++;
   }
           this.Qrycnn.Close();

解决方案 »

  1.   


    public string[] GetGF(string str)
    {
        Qryzhanzhan="select Line_ID  from Busline where Stop_Name ="+"'"+str+"'"; 
        Qrycnn=new SqlConnection(this.Qryzhanzhanstr); 
        this.Qrycnn.Open(); 
        SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);   
        SqlDataReader reader=cmd.ExecuteReader(); 
        int o =0; 
        string[] gf=new string[50];  
        while(reader.Read())  
        { 
            gf[o]=reader["Line_ID"].ToString(); o++; 
        } 
        this.Qrycnn.Close();
        return gf;
    }
      

  2.   

    public ArrayList list()
    {
       Qryzhanzhan="select Line_ID  from Busline where Stop_Name ="+"'"+this.textBox2.Text.ToString().Trim()+"'"; 
       Qrycnn=new SqlConnection(this.Qryzhanzhanstr); 
       this.Qrycnn.Open(); 
       SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);   
       SqlDataReader reader=cmd.ExecuteReader();
       ArrayList li; 
       while(reader.Read())  
       { 
       li.add(reader["Line_ID"].ToString());; 
       } 
               this.Qrycnn.Close();
    }
      

  3.   

    public ArrayList list() 

       Qryzhanzhan="select Line_ID  from Busline where Stop_Name ="+"'"+this.textBox2.Text.ToString().Trim()+"'";  
       Qrycnn=new SqlConnection(this.Qryzhanzhanstr);  
       this.Qrycnn.Open();  
       SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);    
       SqlDataReader reader=cmd.ExecuteReader(); 
       ArrayList li;  
       while(reader.Read())   
       {  
       li.add(reader["Line_ID"].ToString());;  
       }     
       this.Qrycnn.Close(); 
       return li;
    }嘿嘿...丟三落四的