0
我有TableAdapter名稱ballotsTableAdapter,我想用它查詢我的數據庫表選票而不將它作爲查詢添加到表中,如果有意義的話。使用tableadapter如何在頁面後面的代碼中查詢我的db表
Dim adapter As New eVoteTableAdapters.ballotsTableAdapter
Dim ballot_IDIn As Integer = ballot_ID
Dim name As String
Dim sd As Date
Dim ed As Date
name = CType(adapter.Adapter.SelectCommand.ExecuteScalar(SELECT name FROM ballots WHERE ballod_ID = @ballot_IDIn), String)
sd = CType(adapter.Adapter.SelectCommand.ExecuteScalar(SELECT startDate FROM ballots WHERE ballod_ID = @ballot_IDIn), Date)
ed = CType(adapter.Adapter.SelectCommand.ExecuteScalar(SELECT endDate FROM ballots WHERE ballod_ID = @ballot_IDIn), Date)
對不起,我很確定這是一個業餘愛好者的問題。
用'''圍住你的查詢使它成爲一個字符串 - 'SELECT name FROM ballots WHERE ballod_ID = @ ballot_IDIn'變成'$「SELECT name FROM ballots WHERE ballod_ID = {ballot_IDIn}」' - 對於初學者 –
我只是這樣做,並得到錯誤:對象引用未設置爲對象的實例。 – JayyCodez
@AlexM。,請不要建議使用字符串連接來創建SQL查詢,即使對於初學者。 – Fabio