![](/img/trans.png)
[英]How to fix the " The multi-part identifier "word" could not be bound" error
[英]How to solve this error “The multi-part identifier” in ado.net
我有以下查询,它在SQL Server 2008中工作正常,但是当我在ADO.NET中连接时,它显示此错误:
无法绑定多部分标识符“ v.ClientId”。
无法绑定多部分标识符“ v.ClientId”。
无法绑定多部分标识符“ v.ClientID”。
多部分标识符“ v.Fare”无法绑定。
无法绑定多部分标识符“ v.ClientId”。
查询:
SELECT
f.ID, f.ClientID, vc.Name,
f.Fare as FixFares, v.Fare as VehicleFare,
f.FromPostCode, f.ToPostCode, f.[From], f.[To],
v.ClientId, v.IsActive, v.VehicleID, vc.ID
FROM
VehicleFixeFare AS v
INNER JOIN
FixFare f ON v.ClientId = f.ClientId
INNER JOIN
Vehicle vc ON v.ClientId = vc.ClientId
WHERE
v.ClientID = 159
下面的代码
conn = new SqlConnection(Connection1);
conn.Open();
// var LIST=(from a in General.GetQueryable<Ve>)
string Query = "select f.ID, f.ClientID, vc.Name, f.Fare as FixFares, v.Fare as VehicleFare, f.FromPostCode, "+
"f.ToPostCode, f.[From], f.[To], v.ClientId, v.IsActive, v.VehicleID, vc.ID " +
"from VehicleFixeFare as v"+
"inner join FixFare f on v.ClientId = f.ClientId inner join Vehicle vc on v.ClientId = vc.ClientId where v.ClientID =" + ClientID;
SqlDataAdapter ad = new SqlDataAdapter(Query, conn);
dt = new DataTable();
ad.Fill(dt);
我将像这样执行代码,它将消除空间问题,该问题很可能是导致错误的原因,并且可读性更好。
string Query =
@"select f.ID, f.ClientID, vc.Name, f.Fare as FixFares, v.Fare as VehicleFare, f.FromPostCode,
f.ToPostCode, f.[From], f.[To], v.ClientId, v.IsActive, v.VehicleID, vc.ID
from VehicleFixeFare as v
inner join FixFare f on v.ClientId = f.ClientId
inner join Vehicle vc on v.ClientId = vc.ClientId where v.ClientID =" + ClientID;
这是由于空间问题。 在每行的开头和结尾留一些空间,您的问题将得到解决。
string Query = " select f.ID, f.ClientID, vc.Name, f.Fare as FixFares, v.Fare as VehicleFare, f.FromPostCode, "+
" f.ToPostCode, f.[From], f.[To], v.ClientId, v.IsActive, v.VehicleID, vc.ID " +
" from VehicleFixeFare as v "+
" inner join FixFare f on v.ClientId = f.ClientId inner join Vehicle vc on v.ClientId = vc.ClientId where v.ClientID =" + ClientID;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.