I have an issue with trying to get a SqlDataSource working. here is the ASP.net code:

    <asp:SqlDataSource id="SqlDataSource2" runat="server"
           ConnectionString="<%$ ConnectionStrings:connection %>"
           SelectCommand="SELECT [term] [FROM[Ceremony]] order by term">
    </asp:SqlDataSource>

The exception Detail is: System.Data.SqlClient.SqlException: unclosed quotation mark after the character string 'FROM [Ceremony] order by term'

I just don't really know what is wrong with the asp.net code? my C# code is working, and the SQL server is up and running. I go into the SQL tool to test out the select command and it works! If anyone can point out any issues of this code that would be great!

p.s. the connection string works fine also.

有帮助吗?

解决方案

The brackets around the FROM clause are not necessary. You only need to use them when your column/table names have spaces or they are a reserved SQL keyword.

Change SQL to:

SELECT [term] FROM [Ceremony] order by term

其他提示

Try this...

<asp:SqlDataSource id="SqlDataSource2" runat="server"
           ConnectionString="<%$ ConnectionStrings:connection %>"
           SelectCommand="SELECT [term] FROM [Ceremony] order by term">
    </asp:SqlDataSource>

You had a weird nested bracket syntax. Don't wrap the "FROM" word in brackets.

<asp:SqlDataSource id="SqlDataSource2" runat="server"
           ConnectionString="<%$ ConnectionStrings:connection %>"
           SelectCommand="SELECT [term] FROM[Ceremony] order by [term]">
    </asp:SqlDataSource>

If term and Ceremony are not a keyword then i think do not need to include []

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top