不能从

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);

}

以上是 不能从 的全部内容, 来源链接: utcz.com/qa/260140.html

回到顶部