我正在使用 GridView 从本地数据库读取数据,但出现未处理的异常。
页面显示这些消息:
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
下面是web.config中的连接字符串
<connectionStrings>
<add name="automobileDB"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\
automobileDB.mdf; Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
下面是我在 webform 中的 GridView 代码:
<asp:SqlDataSource ID="ADDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:automobileDB %>"
SelectCommand="SELECT * FROM [Advertisements]" >
</asp:SqlDataSource>
<div>
<asp:GridView ID="AddGridView" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="list" DataKeyNames="Id"
DataSourceID="ADDataSource" GridLines="None">
<Columns>
<asp:BoundField DataField="topic" HeaderText="First Name" />
<asp:BoundField DataField="Brand" HeaderText="Last Name" />
<asp:BoundField DataField="Model" HeaderText="Phone" />
<asp:BoundField DataField="Year" HeaderText="Email" />
</Columns>
</asp:GridView>
</div>
这里有什么异常(exception)?
谢谢
最佳答案
根据您在 web.config 中编写连接字符串的方式,|DataDirectory|\
和 automobileDB.mdf
之间有一些空间。将您的连接字符串更改为此:
<connectionStrings>
<add name="automobileDB"
connectionString="Data Source=(LocalDB)\v11.0;
AttachDbFilename=|DataDirectory|\automobileDB.mdf; Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
关于c# - 通过gridview显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25963046/