连接两个表时填充数据集创建问题 [英] Filling Data Set Creating Problem when joining two Table

查看:59
本文介绍了连接两个表时填充数据集创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,我想从两个表中将其绑定,即一个表中的id和另一表中的描述
在填充数据集时出现Sql异常
查询绑定下拉列表为

I have one DropDown List I want to bind it from Two table i.e id from one table and description in another table
on Filling the data Set giving Sql Exception
The Query For binding Drop Down list is

SELECT     
CustomerGroupContacts.cusg_id,
CustomerGroupContacts.cusg_id+'___'+CustomerIDs.cusid_name as customername
FROM        
CustomerGroupContacts INNER JOIN
CustomerIDs ON CustomerGroupContacts.cusg_id = CustomerIDs.cusg_id

推荐答案

我认为CustomerGroupContacts.cusg_id是整数,将其转换为varchar,然后附加到客户名称.

I think CustomerGroupContacts.cusg_id is integer, convert this to varchar and then append to customer name.

SELECT     
CustomerGroupContacts.cusg_id,
CAST(CustomerGroupContacts.cusg_id AS varchar(20)) + '___' + CustomerIDs.cusid_name as customername
FROM        
CustomerGroupContacts INNER JOIN
CustomerIDs ON CustomerGroupContacts.cusg_id = CustomerIDs.cusg_id<pre lang="SQL">


是查询在SQL查询分析器中返回的值吗?如果是,则请检查您的代码.您可能会遗漏某些内容.
请输入以下示例代码
is the query returning you the value in SQL query analyzer ?? if yes then plz check ur code.U might b missing something.
Pls chk the following sample code
string strConnection = "Server=;Database=Testing;user ID=;password=; ";
           SqlConnection sqlConn = new SqlConnection(strConnection);
           string strQuery = "UR QUERY ";
           sqlConn.Open();
           SqlCommand sqlComm = new SqlCommand(strQuery,sqlConn);
           SqlDataAdapter sqa= new SqlDataAdapter(sqlComm);
           DataSet  ds=new DataSet();
           sqa.Fill(ds);


我认为下拉列表仅访问一个值.
i think dropdown access only one value..


这篇关于连接两个表时填充数据集创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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