爲什麼這回空?的ExecuteScalar總是調用標量值函數時返回null
//seedDate is set to DateTime.Now; con is initialized and open. Not a problem with that
using (SqlCommand command = new SqlCommand("fn_last_business_date", con))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@seed_date", seedDate);//@seed_date is the param name
object res = command.ExecuteScalar(); //res is always null
}
但是,當我直接在數據庫中調用這個如下:
select dbo.fn_last_business_date('8/3/2011 3:01:21 PM')
returns '2011-08-03 15:01:21.000'
這是結果,我希望看到,當我把它從代碼
爲什麼,爲什麼,爲什麼?
我沒有問題,返回值f rom的SQL函數。它做它應該做的。我的問題是在C#代碼。我不明白爲什麼如果我傳入一個有效的@seed_date,結果總是爲空;如果有幫助,我可以粘貼sql_function代碼。關於我的sql_function唯一特別的是它使用遞歸...可能是我的問題?那會很奇怪。 – Icarus
實際上是fn_last_business_date存儲過程嗎?如果不能確保你添加的選擇,使命令類型文本(見我的編輯) –
呵呵呵,我只是回答GBN,我曾想過這樣做,但我認爲這是不優雅;)我會嘗試它,如果它的作品,我會給你應有的信貸。謝謝。 – Icarus