无法绑定多部分标识符“System.Data.DataRowView”。“SQL SERVER + VB.NET

时间:2013-06-26 15:24:49

标签: sql-server vb.net datagridview combobox adp

我正在创建一个小型数据库,使用SQL Server作为后端,VB作为前端,我几乎使其工作,但我偶然发现了这个错误:

  

“类型'System.Data.SqlClient.SqlException'的未处理异常   发生在System.Data.dll

中      

附加信息:多部分标识符   “System.Data.DataRowView”无法绑定。“

下面提供的代码非常感谢一些帮助

干杯

Imports System.Data.SqlClient
Public Class searchDialog

    Private Sub searchDialog_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'SearchDataSet.Books' table. You can move, or remove it, as needed.
        Me.BooksTableAdapter.Fill(Me.SearchDataSet.Books)

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim query As String = "select * from Books where " + colNames.SelectedValue.ToString + " LIKE " + "'%" + colValues.Text + "%'"
        BooksTableAdapter.Connection.Open()

        Dim adp As New SqlDataAdapter(query, BooksTableAdapter.Connection.ConnectionString)

        adp.Fill(ds, query)

        BooksTableAdapter.Connection.Close()

        filteredRecords.DataSource = ds
        filteredRecords.DataMember = "Books"
    End Sub
End Class

1 个答案:

答案 0 :(得分:2)

您的错误就在这一行:

adp.Fill(ds, query)

您可以填充数据集。但是,.Fill()的第二个参数应该是数据表的名称。您正在尝试将Query用作表名,但它太长且太复杂。你最好用这样的东西:

adp.Fill(ds, "Books")