1

我正在使用 SQL Server 作为后端和 VB 作为前端来制作一个小型数据库,我几乎让它工作了,但是我偶然发现了这个错误:

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

附加信息:无法绑定多部分标识符“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
4

1 回答 1

2

您的错误在这一行:

adp.Fill(ds, query)

您可以很好地填充数据集。但是,.Fill() 的第二个参数应该是数据表的名称。您正在尝试使用 Query 作为表名,但它太长且太复杂。使用这样的方法会更好:

adp.Fill(ds, "Books")
于 2013-06-26T15:42:54.637 回答