Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在while循环中访问数据_C#_Sql Server - Fatal编程技术网

C# 在while循环中访问数据

C# 在while循环中访问数据,c#,sql-server,C#,Sql Server,我正在用c#和SQL server开发一个web API。如果我想访问while循环中的数据,例如:objtoken.customer\u id,我该怎么做,以便我可以使用它进行进一步的开发 While循环 while (_Reader.Read()) { Login_Model objtoken = new Login_Model(); objtoken.user_id = _Reader["user_id"].ToString(); objt

我正在用c#和SQL server开发一个web API。如果我想访问while循环中的数据,例如:
objtoken.customer\u id
,我该怎么做,以便我可以使用它进行进一步的开发

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

你的问题不清楚-你有
objtoken.customer\u id
,你可以使用它。我如何在loop@zmbq外使用它?你有很多客户id。您想使用哪一个?第一个@zmbq查看
\u return
集合?