【发布时间】:2014-09-27 23:09:14
【问题描述】:
我在 SQL Server 数据库中有一个包含许多列的表,但重要的列是 LoggedState 和 InteractionType。
我需要找出中断代理的数量和空闲代理的数量。
我尝试过的
SqlCommand GraphCmd = new SqlCommand("getAgentStatues", Graphsqlcon);
SqlParameter tdate = new SqlParameter();
GraphCmd.CommandType = CommandType.StoredProcedure; ;
SqlDataAdapter DAGraph = new SqlDataAdapter(GraphCmd);
DataSet DSGraph = new DataSet();
DSGraph.Clear();
DAGraph.Fill(DSGraph);
DataTable DTgraph = new DataTable();
DTgraph = DSGraph.Tables[0];
int numberOfBreakAgents = 0;
int numberOfIdelAgents = 0;
foreach (DataRow row in DTgraph.Rows)
{
String LoggedState = row["LoggedState"].ToString().Trim().ToLower();
String InteractionType = row["InteractionType"].ToString();
if (LoggedState == "break")
{
numberOfBreakAgents++;
}
else if ((LoggedState == "activo") && (row["InteractionType"] == DBNull.Value))
{
numberOfIdelAgents++;
}
}
它工作得很好,但我想问是否有办法(比如分组)来避免foreach 声明
【问题讨论】:
-
这可能不关我的事,但你似乎在第 3 行多了一个不应该出现的分号。
-
@Matthijs 谢谢你的权利
标签: c# sql sql-server datatable