2013-06-26 132 views
1

我正在製作一個小型數據庫,使用SQL Server作爲後臺,VB作爲前端,我幾乎已經制作了它的工作,但是我也偶然發現了這個錯誤:無法綁定多部分標識符「System.Data.DataRowView」SQL SERVER + VB.NET

"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, query) 

     BooksTableAdapter.Connection.Close() 

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

驗證'colNames.SelectedValue.ToString'是什麼等於。我相信它會產生'System.Data.DataRowView'。 –

+0

是過濾記錄一個數據網格還是別的東西? – tgolisch

回答

2

你的錯誤是在這條線:

adp.Fill(ds, query) 

你很好地填充數據集。但是,.Fill()的第二個參數應該是數據表的名稱。您試圖將查詢用作表名,但它太長而且很複雜。你會更好用這樣的事情:

adp.Fill(ds, "Books") 
+0

嗨歡呼tgolisch我曾嘗試做你的建議之前,但仍然繼續得到相同的錯誤 – user2520014

相關問題