1

I am making a small database using SQL Server as the back and VB as the front end, I have nearly made it work however I have stumbled across this error:

"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: The multi-part identifier "System.Data.DataRowView" could not be bound."

My code is provided below would really appreciate some help

Cheers

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
gofr1
  • 15,741
  • 11
  • 42
  • 52
user2520014
  • 73
  • 2
  • 11

1 Answers1

2

Your error is on this line:

adp.Fill(ds, query)

You are fine filling the dataset. However, the 2nd argument to .Fill() is supposed to be the name of the data table. You are trying to use the Query as a table name, but it is too long and complex. You would be better off with something like this:

adp.Fill(ds, "Books")
tgolisch
  • 6,549
  • 3
  • 24
  • 42