【问题标题】:How to set the database in ASP.Net如何在 ASP.Net 中设置数据库
【发布时间】:2010-01-04 18:31:29
【问题描述】:

我在位置 xmachina\sqlexpress 有一个名为 News 的数据库,News 有一个表 NewsTable。我如何告诉 ASP 查看新闻数据库?它是 SelectCommand 的一部分吗?还是 webconfig 变量?

现在我得到一个 [SqlException (0x80131904): Invalid object name 'NewsTable'。]

web.config

<add name="NewsTableConnectionString" connectionString="Data Source=XMACHINA\SQLEXPRESS;Integrated Security=True" providerName="System.Data.SqlClient" />

默认.aspx

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
   ConnectionString="<%$ ConnectionStrings:NewsTableConnectionString %>"
       ProviderName="<%$ ConnectionStrings:NewsTableConnectionString.ProviderName %>" 
       SelectCommand="SELECT [NewsHeadline] FROM [NewsTable]">
</asp:SqlDataSource>

【问题讨论】:

    标签: asp.net sql data-binding


    【解决方案1】:

    在 web.config 中的连接字符串设置中使用它

    数据库=新闻;

    有关详细信息,请参阅以下站点:link text

    【讨论】:

      【解决方案2】:

      我需要这个“初始目录”属性

      <add name="NewsTableConnectionString" connectionString="Data Source=XMACHINA\SQLEXPRESS;Integrated Security=True;Initial Catalog=News" providerName="System.Data.SqlClient" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-12
        • 1970-01-01
        • 2020-02-22
        • 1970-01-01
        • 2011-07-20
        • 2012-12-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多