【问题标题】:read sql schema in sqldatasource在 sqldatasource 中读取 sql 模式
【发布时间】:2014-01-12 10:41:56
【问题描述】:

我在我的数据库中使用了一些 SQL 架构,

CoursesProperties.tbl_Countries
CoursesProperties.tbl_Rating

在我的 .net 应用程序中,我使用 SqlDataSourse 直接填充 GridView

<asp:SqlDataSource ID="SqlDataSourceLocations" runat="server" 
     ConnectionString="<%$ ConnectionStrings:TrainingConnectionString %>" 
     SelectCommand="SELECT CountryE FROM [CourseProperties.tbl_Countries]">
</asp:SqlDataSource>

当我运行我的应用程序时,我收到了这个错误:

对象名称“CourseProperties.tbl_Countries”无效。

即使我删除了架构也会出错

对象名称“tbl_Countries”无效。

我想过从数据库中删除架构,但我想我们先寻求专家的帮助。

有什么建议吗?

【问题讨论】:

    标签: c# asp.net sql .net sql-server-2008


    【解决方案1】:

    方括号应该是:

    SelectCommand = "SELECT CountryE FROM [CourseProperties].[tbl_Countries]"
    

    或完全省略它们:

    SelectCommand = "SELECT CountryE FROM CourseProperties.tbl_Countries"
    

    但不在架构周围 AND 表名

    [只有在列名(或标识符)中使用空格、关键字或特殊字符时才需要方括号,应尽量避免使用。]

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多