0

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.

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for replying so fast, I will try it out :-)
2

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.

Comments

0
<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 []

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.