0

I have two tables tblCarrier and tblCustomer. Both tables are INNER JOIN and have the same column name which is company name. The problem is when I use the databinding process

<%#DataBinder.Eval(Container.DataItem, "CompanyName")%> to get the back the customer company name, it gives me back the carrier company name. What I notice from my query is that it gets back the company name based on the order sequence in the query statement.

For example

"SELECT tblCarrier.CarrierID,tblLoadMaster.Salesperson,tblLoadMaster.Status, tblCarrier.CompanyName, tblCustomer.CompanyName"

This T-SQL statement will bring back the carrier company name, but if I were to put the tblCustomer.CompanyName before tblCarrier.CompanyName, it will then bring back the customer company.

Is there way to databind the columns to get the results based on the cross reference table?

4

1 回答 1

2

您可以为冲突的列名取别名

SELECT tblCarrier.CarrierID,tblLoadMaster.Salesperson,tblLoadMaster.Status,  
  tblCarrier.CompanyName as Car_CompanyName, 
  tblCustomer.CompanyName as Cus_CompanyName;

然后在 Eval 调用中使用别名而不是列名。

<%#DataBinder.Eval(Container.DataItem, "Cus_CompanyName")%>
于 2013-01-07T14:57:09.227 回答