我正在製作一個小型數據庫,使用sql server作爲後端,vb作爲前端,我幾乎已經使其工作,但是我已經絆倒了跨越這個錯誤:無法綁定多部分標識符「System.Data.DataRowView」。
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.
這裏是我的代碼:
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, "Books")
BooksTableAdapter.Connection.Close()
filteredRecords.DataSource = ds
filteredRecords.DataMember = "Books"
End Sub
End Class
什麼是colNames和colValues? – Chris
如果您使用Visual Studio,請在設置查詢的行上設置斷點。然後調試下一步(f8)。什麼是變量「查詢」?它看起來像是你的組合框(colNames)沒有設置value屬性,或者它被設置爲一個數據行。 – tgolisch
在你的加載方法中,你可能想把你的Me.BooksTableAdapter.Fill放在!IsPostBack裏面...... –