简体   繁体   English

SqlDataSource选择语句语法错误

[英]SqlDataSource select statement syntax error

I'm working on an ASP page for a project, which should provide an interface for the user to maintain information on local little league baseball and softball. 我正在为一个项目的ASP页面工作,该页面应为用户提供一个界面,以维护有关本地小联盟棒球和垒球的信息。 I keep getting an error: 我不断收到错误消息:

Syntax error in FROM clause. FROM子句中的语法错误。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

when attempting to use a SqlDataSource with the following SelectCommand: 尝试通过以下SelectCommand使用SqlDataSource时:

SELECT tblPlayers.PlayerCode, tblPlayers.First_Name,
                          tblPlayers.Last_Name, tblPlayers.Gender,
                          tblPlayers.Date_of_Birth, tblPlayers.League_age,
                          tblPlayers.InActiveStatus, 
                          tblParentMaster.ParentFirst+' '+tblParentMaster.Parentlast AS Parent_1,
                          tblParentMaster_2.ParentFirst+' '+tblParentMaster_2.ParentLast AS Parent_2,
                          tblPlayers.Birth_Certificate_on_file
                     FROM tblPlayers
                     JOIN tblParentMaster
                       ON tblPlayers.HOHCode = tblParentMaster.ParentCode
                     JOIN tblParentMaster AS tblParentMaster_2
                       ON tblPlayers.Parent2Code = tblParentmaster_2.ParentCode
                    WHERE (tblPlayers.PlayerCode = @PlayerCode)

In this code, @PlayerCode is the SelectedValue attribute of a GridView control on the page. 在此代码中,@ PlayerCode是页面上GridView控件的SelectedValue属性。 I've already declared the ControlParameter for the SqlDataSource with the above SelectCommand: 我已经使用上面的SelectCommand声明了SqlDataSource的ControlParameter:

<SelectParameters>
        <asp:ControlParameter ControlID="selectPlayerGridView" Name="PlayerCode"
            PropertyName="SelectedValue" Type="String" />
    </SelectParameters>

The SQL select statement is being used to populate data into a FormView. SQL select语句用于将数据填充到FormView中。 I'm not bothering to post the code for the FormView, sine it's a large chunk of code. 我不必为FormView发布代码,因为这是一大堆代码。 I'm not brand new to SQL, but I don't have a lot of practical experience, either. 我对SQL并不陌生,但是我也没有很多实践经验。 Can someone please point out the syntax error? 有人可以指出语法错误吗? I appreciate any help, thanks. 感谢您的帮助,谢谢。

AS you said in comment 正如您在评论中所说

If you are using .mdb file then it is an MS Access database then It should be connected using OleDb providers 如果使用的是.mdb文件,则它是MS Access database ,则应使用OleDb providers进行连接

and then your query should be like the following 然后您的查询应如下所示

SELECT tblPlayers.PlayerCode, tblPlayers.First_Name,
                          tblPlayers.Last_Name, tblPlayers.Gender,
                          tblPlayers.Date_of_Birth, tblPlayers.League_age,
                          tblPlayers.InActiveStatus, 
                          tblParentMaster.ParentFirst & ' ' & tblParentMaster.Parentlast AS Parent_1,
                          tblParentMaster_2.ParentFirst & ' ' & tblParentMaster_2.ParentLast AS Parent_2,
                          tblPlayers.Birth_Certificate_on_file
                     FROM tblPlayers
                     JOIN tblParentMaster
                       ON tblPlayers.HOHCode = tblParentMaster.ParentCode
                     JOIN tblParentMaster AS tblParentMaster_2
                       ON tblPlayers.Parent2Code = tblParentmaster_2.ParentCode
                    WHERE (tblPlayers.PlayerCode = @PlayerCode)

Replace + with & &替换+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM