我試圖從數據庫中檢索會議的特定日期以顯示在網頁上。閱讀ConferenceID如下所示:System.Data.SqlClient.SqlException:無效的列名'conferID'
conferID = reader["ConferenceID"].ToString();
我想的頁面從ConferenceID =僅顯示日期「3」,但我也從ConferenceID =獲得日期「1」和ConferenceID =「2」時,我從下面的代碼中刪除(ConferenceID = conferID)。但是,如果我將(ConferenceID = conferID)添加回代碼,則頁面打破了。如果我將這些代碼放在SQL中進行測試並更改(ConferenceID = conferID)爲(ConferenceID ='3'),它就會起作用。我現在失去了。任何幫助表示讚賞。
SqlCommand GetDates = new SqlCommand(@"
WITH x AS (
select MAX(ConferenceID) as ConferenceID, row_number() over(order by D.Dates) as SN, D.Dates
from Conference as T
inner join master..spt_values as N
on N.number between 0 and datediff(day, T.ConferenceBeginDate, T.ConferenceEndDate)
cross apply (select dateadd(day, N.number, T.ConferenceBeginDate)) as D(Dates)
where N.type ='P' AND (ConferenceID = conferID) group by ConferenceID, D.Dates
)
SELECT ConferenceID, SN, Dates
FROM x
WHERE SN <> (Select MAX(SN) from x) AND (ConferenceID = conferID)
GROUP BY ConferenceID, SN, Dates", conn);
你是正確的添加一個參數,但我認爲最後一個語句'GetDates.Parameter ...(「ConferenceID」)應該是(「@ConferenceID」)。我將你的答案標記爲有用。謝謝! –