I am having an issue with the way asp.net/c# is generating mySQL select statements when setting up my datasource control.
I am pretty sure I have a setting set wrong, but cannot figure out what it is.
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:demers_dbConnectionString3 %>"
ProviderName="<%$ ConnectionStrings:demers_dbConnectionString3.ProviderName %>"
SelectCommand="SELECT * FROM [test_table]"></asp:SqlDataSource>
As you can see, the brackets around test_table are square, and this statement throws a syntax error.
When I manually change the brackets to:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:demers_dbConnectionString3 %>"
ProviderName="<%$ ConnectionStrings:demers_dbConnectionString3.ProviderName %>"
SelectCommand="SELECT * FROM (test_table)"></asp:SqlDataSource>
The error goes away and my page runs.
I will have to create a lot of mySQL links as I develop my site, so I was hoping to fix the setting that I have wrong.
Ideas???
This is the associated config file.
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="demers_dbConnectionString" connectionString="server=localhost;user id=MYID;password=MYPASSWORD;database=demers_db"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
No need of those []
; since you are using MySQL
you should use backtique (`) for escaping. Your select command should look like
SelectCommand="SELECT * FROM `test_table`"
(or) just below since there is no spaces in your table name
SelectCommand="SELECT * FROM test_table"
Also make sure that you are using MySQL connector provider ProviderName="MySql.Data.MySqlClient"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.