2014-09-21 2 views
2

Я использую представление сетки для чтения данных из локальной базы данных, но я получаю необработанное исключение.Отображение данных через 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> 

Ниже приведен мой решетчатый код вида в веб-форму:

<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> 

Что дает исключение здесь?

Спасибо

+1

Вы можете проверить, есть ли какое-либо пространство между 'DataDirectory \\' и 'carDB.mdf'? – ekad

+0

@ekad было пространство, и я удалил его, теперь его работа. Большое спасибо. – Chris

ответ

1

Основываясь на том, как вы пишете строку подключения в файле 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> 
Смежные вопросы