我正在使用c#和SQL Server开发Web API。如果我想访问数据(即objtoken.customer_id
while循环中),该怎么做,以便可以将其用于进一步的开发。
While循环
while (_Reader.Read())
{
Login_Model objtoken = new Login_Model();
objtoken.user_id = _Reader["user_id"].ToString();
objtoken.customer_id = _Reader["customer_id"].ToString();
_return.Add(objtoken);
}
如果要访问第一个customer_id,请将其存储在循环外的变量中:
string first_customer_id = null;
while (_Reader.Read())
{
// your original loop content
if (first_customer_id == null)
first_customer_id = objtoken.customer_id;
}
// Here first_customer_id holds the first customer id, or is null if there were no customers
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句