經過一番研究,似乎XSD有一個名爲ConnectionModifier的屬性。
要找到它,請在您的XSD圖上單擊圖的TableAdapter部分(其中查詢已定義)。
在屬性窗口中,將ConnectionModifier更改爲Public,然後單擊Save。 (這似乎更改屬性爲頁面上的所有數據集了。)
回到你的網站的主要代碼,您現在就可以做這樣的事情:
'declare the adapter as normal
Dim AdapterTest As New DataSetTestTableAdapters.TestTableAdapter
'pass the new connection object into the now visible property
AdapterTest.Connection = New Data.SqlClient.SqlConnection("Data Source=Myserver;Initial Catalog=TEST;Integrated Security=True;")
只需要一個連接對象。
我還沒有給這個適當的測試! Unfortunatley,每當你從XSD聲明一些東西時,必須傳遞一個新的連接對象。