【发布时间】:2016-11-17 14:01:01
【问题描述】:
我在访问数据库上进行了 sql 查询。在 datagridview2 中,我在第一列中看到第二列中安装的程序有多少台计算机安装了该程序。
col1 col2
xxxx 1
yyyy 2
zzzz 3
OleDbCommand command2 = new OleDbCommand();
command2.Connection = connection;
string query = "SELECT Item_1, count(Item_1) FROM (SELECT Item_1 FROM Audit_data where Category_ID = 500) group by Item_1 having (count(*)>0) ";
command2.CommandText = query;
OleDbDataAdapter da1 = new OleDbDataAdapter(command2);
da1.Fill(dt2);
dataGridView2.DataSource = dt2;
dataGridView2.AutoResizeColumns();
datagridview3 仅包含在 datagridview2 上更改选择时安装程序的计算机名称:
string selcell = Convert.ToString(dataGridView2.CurrentCell.Value);
OleDbCommand command3 = new OleDbCommand();
command3.Connection = connection;
string query = "select distinct Fully_Qualified_Domain_Name from Audit_Data, Computer_master where Item_1= '"+selcell+"' and category_id=500 and Audit_Data.computer_id = Computer_master.computer_id ";
command3.CommandText = query;
OleDbDataAdapter da3 = new OleDbDataAdapter(command3);
da3.Fill(dt3);
dataGridView3.DataSource = dt3;
dataGridView3.AutoResizeColumns();
我想运行这些查询来获取所有已安装计算机名称的软件。我不知道如何对 col 1 上的所有数据进行查询并将其导出到 csv 中。
xxxx; 1; qwer_pc
yyyy; 2; asdf_pc;
qwer_pc
zzzz; 3; asdf_pc;
qwer_pc;
yxcv_pc
有人可以帮忙解决这个问题吗? 或者我可以以某种方式将这两个查询结合起来吗?
【问题讨论】: