• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

不能从

c/c++ 来源:user2068294 4次浏览

class cAccess 
    { 
     private static string usn1; 

     public static string usnt 
     { 
      set 
      { 
       usn1 = value; 
      } 
      get 
      { 
       string[] s = new string[3]; 
       DataSet dsa = new DataSet(); 
       SqlDataAdapter adp = new SqlDataAdapter(); 
       adp.SelectCommand = new SqlCommand("select * from access where id=" + usn1, connection.setCon()); 
       adp.Fill(dsa, "t"); 
       DataRow DBrow = dsa.Tables["t"].Rows[0]; 
       for (int i = 0; i < 3; i++) 
       { 
        s[i] = DBrow.ItemArray.GetValue(i).ToString(); 
       } 
       return s; 
      } 
     } 
    } 

我想从类返回s阵列,但返回变量时,我开始调试,它表明这个错误:不能从

The name ‘s’ does not exist in the current context. Code works true but can’t return s.


===========解决方案如下:

你不能返回string[]string

尝试:

class cAccess 
{ 
    private static string usn1; 

    public string usnt 
    { 
     set 
     { 
     usn1 = value; 
     } 
     get 
     { 
     StringBuilder s = new StringBuilder(); 
     DataSet dsa = new DataSet(); 
     SqlDataAdapter adp = new SqlDataAdapter(); 
     adp.SelectCommand = new SqlCommand("select * from access where id=" + usn1, connection.setCon()); 
     adp.Fill(dsa, "t"); 
     DataRow DBrow = dsa.Tables["t"].Rows[0]; 
     for (int i = 0; i < 3; i++) 
     { 
     s.Append(DBrow.ItemArray.GetValue(i).ToString()); 
     } 

     usn1 = s.ToString(); 
     return(usn1); 
} 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)