SQL - 选择distinct [英] SQL - select distinct

查看:168
本文介绍了SQL - 选择distinct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用select disctinct语句与我的sql数据库表中的2个字段。这是我的代码。

I used the select disctinct statement with 2 fields from my sql database table. Here is my code.

myCommand = New SqlCommand("SELECT DISTINCT Author FROM tblBook UNION SELECT DISTINCT BookCode FROM tblBook",myConnection)
 myAdapter = New SqlDataAdapter(myCommand)
 myAdapter.Fill(myDataSet, "tblBook")
 cboAuthor.DataSource = myDataSet.Tables(0)
 cboAuthor.DisplayMember = "Author"
 cboAuthor.DisplayValue = "BookCode"

,它会产生错误:无法绑定到新成员。参数名称:value 。请帮助

and it generates error : cannot bind to the new member. Parameter name:value. Please help

推荐答案

您在sql语句中只选择了一列,作者。
BookCode不存在,所以它不会在数据集中。

you have selected only one column in your sql statement, Author. BookCode isn't present so it won't be in the dataset either.

在Sql语句中包含BookCode,它将被修复

Include the BookCode in the Sql Statement and it will be fixed

这篇关于SQL - 选择distinct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆