如何在一个数据集中进行两个选择查询 [英] how to take two select query in one dataset
本文介绍了如何在一个数据集中进行两个选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码是
my code is
string search_query = @"SELECT distinct DENSE_RANK()OVER(ORDER BY reg_no) as srno,(svi.reg_no),
(university_info.university_name) as university_name,
(svi.directors) as vc_dir_name,
(svi.university_id) as uni_id,
(svi.organization_id) as org_id,
(svi.university_id) as uni_id,
(case when svi.mous_signed = '0' then 'Yes' else 'No' end) as mou_singed,
(svi.number_student) as number_student,
(case when svi.prop_mous = '0' then 'Yes' else 'No' end) as prop_mous,
(svi.number_mous) as number_mous
FROM state_visit_info svi INNER JOIN
country_info ON svi.country_code = country_info.country_code INNER JOIN
university_info ON svi.university_id = university_info.university_id INNER JOIN
organization ON svi.organization_id = organization.organization_id
where svi.organization_id='04' and svi.country_code='040'
SELECT distinct DENSE_RANK()OVER(ORDER BY reg_no) as srno,(svi.reg_no),
(university_info.university_name) as university_name,
(svi.directors) as vc_dir_name,
(svi.university_id) as uni_id,
(svi.organization_id) as org_id,
(svi.university_id) as uni_id,
(case when svi.mous_signed = '0' then 'Yes' else 'No' end) as mou_singed_fin,
(svi.number_student) as number_student_fin,
(case when svi.prop_mous = '0' then 'Yes' else 'No' end) as prop_mous_fin,
(svi.number_mous) as number_mous
FROM state_visit_info svi INNER JOIN
country_info ON svi.country_code = country_info.country_code INNER JOIN
university_info ON svi.university_id = university_info.university_id INNER JOIN
organization ON svi.organization_id = organization.organization_id
where svi.organization_id='04' and svi.country_code='054'";
SqlCommand sql_cmd = new SqlCommand(search_query);
//SqlDataReader rdr_university = Ou4.GetReader(search_query);
SqlDataAdapter adp = new SqlDataAdapter(search_query, con);
DataSet ds = new DataSet();
adp.Fill(ds);
我在这里面有两个查询。我想在一个数据集中获取这两个查询的结果,所以我怎么能这样做.... plz帮助我
i have two query here inside one . i want to take result of these two query in one dataset so how can i do this ....plz help me
推荐答案
你可以这样使用它。 。:)
这里有一个例子,根据你的需要修改它
you can use it in this way.. :)
here is an example ,modify it according to your need
string sqlQuery="select * from Table1 select * from Table2";
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString);
SqlCommand sql_cmd = new SqlCommand(sqlQuery, cn);
//SqlDataReader rdr_university = Ou4.GetReader(search_query);
SqlDataAdapter adp = new SqlDataAdapter(sql_cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
//You got two datatable in dataset one is for first query and second for second query
如果您编写两个这样的查询,而不是数据集中有两个数据..:)
If you write two queries like this than you got two datatbles in dataset.. :)
这篇关于如何在一个数据集中进行两个选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文