【发布时间】:2017-04-07 21:24:23
【问题描述】:
请指教;这段代码有什么问题? 给出以下错误...列'xxxx'不属于基础表''。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim connStr As String = ConfigurationManager.ConnectionStrings("FBB-DSL-DBConnectionString").ConnectionString
Dim tablex As New DataTable()
Using conn As New SqlConnection(connStr)
Using cmd As New SqlCommand("sp_columns", conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@table_name", "tbl_EmpRecords")
' get the adapter object and attach the command object to it
Using ad As New SqlDataAdapter(cmd)
' fire Fill method to fetch the data and fill into DataTable
ad.Fill(tablex)
End Using
End Using
End Using
'Creating DataView
Dim view As New DataView(tablex)
Dim dt As DataTable = view.ToTable(False, "COLUMN_NAME" )
CheckBoxList1.DataSource = dt
CheckBoxList1.DataBind()
End If
End Sub
【问题讨论】:
-
view.ToTable 的第二个参数应该是 DataTable 现有列的名称 tablex 你在tablex?
-
是 Tablex 包含一个名为“xxxx”的列
-
对不起,我没有其他解释。您的 TableX 使用系统定义的 sp_column 存储过程填充。此存储过程会生成一个没有名为“xxxxx”的字段的数据表。您尝试使用的列的真实名称是什么?
-
我正在使用 sp_column sp 来提取 tbl_EmpRecords 的列名。结果是 12 列,其中之一称为 EmpUsername 和 EmpGender 。所以我填充了tablex然后需要使用datview过滤结果然后将最终结果分配给cbl。
-
所以你的 tablex 得到了 12 行。在其中一个名为 COLUMN_NAME 的列下有单词 EmpUserName 而另一行,对于同一列,包含单词 EmpGender 如您所见,您没有在 tableX 数据表中有一个名为 EmpGender 或 _EmpUserName 的列我认为我在下面的回答解释了问题
标签: sql-server vb.net ado.net dataview