我有以下查询在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);
答案 0 :(得分:0)
我会像这样做代码,它会消除可能导致错误的空间问题,并且更具可读性。
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;
答案 1 :(得分:0)
这是由于空间问题。在每行的开头和结尾留一些空间,你的问题就会得到解决。
1. Remove Grails version 2.5.5 (if this is already installed)
2. Download/install Grails version 2.5.4
3. Run basic command grails-createapp. This runs fine and an app is created.
4. Remove Grails version 2.5.4
5. Install Grails version 2.5.5 now
6. Run command - grails createapp (this starts working now)