问题描述
上帝啊为什么一次又一次地获得重复的价值请帮我一两个
我的问题:
step1:
我使用此查询从数据库中获取唯一值,我得到了确切的结果
O God Why am getting the repeated values again and again pls some 1 help me
My Prob:
step1:
I used this query to get an unique value from an database and i got exact result
select DISTINCT fnlwgt from Dataset;
第2步:
我使用此查询获取整个记录,这些记录必须与使用连接查询的唯一值匹配,这里是我的代码
Step2:
I used this query to get entire records which must matches the unique value using join query here is my code
da = new SqlDataAdapter("SELECT rule1.Age, rule1.workclass, rule1.fnlwgt, rule1.education, rule1.maritalstatus FROM rule1 INNER JOIN probablity ON rule1.fnlwgt = probablity.fnlwgt", cn.con);
结果如下
53 Self -emp-inc 100029博士结婚 - 公民 - 配偶
53自我实体公司100029博士结婚 - 文明 - 配偶
53自我实体公司100029结婚博士 - civ-spouse
53 Self-emp-inc 100029博士已婚 - 文明配偶
53 Self-emp-inc 100029博士结婚 - 文明配偶
53 Self-emp-inc 100029博士结婚 - 公民配偶
53自我实体公司100029博士结婚 - 公民配偶
53自我 - inc 100029博士结婚 - 公民 - 配偶
53自我实体公司100029博士结婚 - 公民 - 配偶
28私人100219 HS-毕业从未结婚
28私人100219 HS-grad从未结婚
28私人100219 HS-grad从未结婚
28私人100219 HS -grad从未结婚
28私人100219 HS-grad从未结婚
28私人100219 HS-grad从未结婚
28私人100219 HS-grad从未结婚
55 Self-emp-not-inc 100569 HS -grad分离
55 Self-emp-not-inc 100569 HS-grad分离
55 Self-emp-not-inc 100569 HS-grad分开
55 Self-emp-not-inc 100569 HS-grad分开
55 Self-emp-not-inc 100569 HS-grad分离
55自我 - not-inc 100569 HS-grad分离
55 Self-emp-not-inc 100569 HS-grad分离
55 Self-emp-not-inc 100569 HS-grad分离
55 Self-emp-not-inc 100569 HS-grad分离
55 Self-emp-not-inc 100569 HS-grad分离
因此我有近31225条记录
但预期的结果是
53 Self-emp-inc 100029博士结婚 - 文明配偶
28私立100219 HS-grad未婚
55 Self-emp-not-inc 100569 HS -grad分开
我该怎么做才能得到特定的结果请帮助我
Am geting the result as
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
53Self-emp-inc100029DoctorateMarried-civ-spouse
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
28Private 100219HS-grad Never-married
55Self-emp-not-inc100569HS-grad Separated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
55Self-emp-not-inc100569HS-gradSeparated
As such i have nearly 31225 records
But the expected Result is
53Self-emp-inc100029DoctorateMarried-civ-spouse
28Private 100219HS-grad Never-married
55Self-emp-not-inc 100569HS-grad Separated
what should i do to get particular result pls some 1 help me
推荐答案
da = new SqlDataAdapter("SELECT rule1.Age, rule1.workclass, rule1.fnlwgt, rule1.education, rule1.maritalstatus FROM rule1 INNER JOIN probablity ON rule1.fnlwgt = probablity.fnlwgt", cn.con);
to
to
da = new SqlDataAdapter("SELECT DISTINCT rule1.Age, rule1.workclass, rule1.fnlwgt, rule1.education, rule1.maritalstatus FROM rule1 INNER JOIN probablity ON rule1.fnlwgt = probablity.fnlwgt", cn.con);
(注意添加了Distinct关键字。)
(Note the addition of the Distinct key word.)
private void button2_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from rule1",cn.con);
DataTable dtRemoveDuplicate = new DataTable();
da.Fill(dtRemoveDuplicate);
dtRemoveDuplicate = DeleteDuplicateFromDataTable(dtRemoveDuplicate);
dataGridView1.DataSource = dtRemoveDuplicate;
//dataGridView1.DataBind();
}
private DataTable DeleteDuplicateFromDataTable(DataTable dtRemoveDuplicate)
{
DataView dView = new DataView(dtRemoveDuplicate);
string[] arrColumns = { "Age", "workclass", "fnlwgt", "education", "maritalstatus" };
dtRemoveDuplicate = dView.ToTable(true, arrColumns);
return dtRemoveDuplicate;
throw new NotImplementedException();
}
这篇关于使用c#帮助我使用sql querry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!