这个sql命令代码的问题是什么?

时间:2014-10-13 12:16:35

标签: c# sql

string str = string.Format("SELECT User1.NAME,User1.PORT,User1.IP,File1.SIZE FROM ((SELECT UID,FID FROM [User_File] WHERE FID= {0}) AS a) ,[User1],[File1] WHERE  a.UID= User1.UID AND a.FID=File1.FID", id);

SqlCommand GetTableUsers = new SqlCommand(str, MyConnection);

错误是: ')'附近的语法不正确。

1 个答案:

答案 0 :(得分:0)

它看起来有点笨重,我建议你用以下方式重写它:

     SELECT User1.NAME,User1.PORT,User1.IP,File1.SIZE, 
     FROM [User_File],[User1],[File1] 
     WHERE  [User_File].UID= User1.UID AND [User_File].FID=File1.FID and [User_File].FID = {0}

并检查它是否在没有SQL Management Studio错误的情况下运行。