2014-10-20 124 views
0

我配置我的web.config中的SQL Server數據庫,因爲這 需要幫助RSS

<appSettings> 
<add key="OnlineDiscussionSqlCon" value="Data Source=.;Initial Catalog=OnlineDiscussionForum;Integrated Security=True" /> 

這就是做工精細,

(在.aspx文件appSetting值),但我不能在.aspx文件中訪問我的數據庫

我的.aspx文件是

<%@ Page Language="C#" MasterPageFile="~/User/MasterPage.master" AutoEventWireup="true" CodeFile="WelcomePage.aspx.cs" Inherits="User_WelcomePage" Title="Untitled Page" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
<table style="width: 560px; position: static"> 
    <tr> 
     <td align="center" > 
      Wel come To User</td> 
     <td > 
     </td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
     </td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
     </td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
     </td> 
    </tr> 
    <tr> 
     <td colspan="2" align="center"> 
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" 
       DataSourceID="SqlDataSource2" EmptyDataText="There are no data records to display." 
       Style="position: static;" AllowPaging="True" PageSize="4"> 
       <Columns> 
        <asp:BoundField DataField="BookName" HeaderText="BookName" SortExpression="BookName" /> 
       </Columns> 
      </asp:GridView> 
      <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ appSettings:OnlineDiscussionSqlCon %>" 
       DeleteCommand="DELETE FROM [TblNewbookAlert] WHERE [ID] = @ID" InsertCommand="INSERT INTO [TblNewbookAlert] ([BookName]) VALUES (@BookName)" 

       SelectCommand="SELECT [ID], [BookName] FROM [TblNewbookAlert]" UpdateCommand="UPDATE [TblNewbookAlert] SET [BookName] = @BookName WHERE [ID] = @ID"> 
       <DeleteParameters> 
        <asp:Parameter Name="ID" Type="Int32" /> 
       </DeleteParameters> 
       <InsertParameters> 
        <asp:Parameter Name="BookName" Type="String" /> 
       </InsertParameters> 
       <UpdateParameters> 
        <asp:Parameter Name="BookName" Type="String" /> 
        <asp:Parameter Name="ID" Type="Int32" /> 
       </UpdateParameters> 
      </asp:SqlDataSource> 
     </td> 
    </tr> 
</table> 

我嘗試過很多方法,但我沒有得到固定,

請任何一個可以幫助我在這裏。

謝謝。

回答

0

請使用「Data Source = YourServerName \ YourSqlServerInstanceName」而不是「Data Source =」。在web.config文件中。