2013-04-22 161 views
-2

嘛,我倒,如果我傳遞一些參數,無需@符號將參數傳遞給存儲過程無需@符號

public static int Run(string command,string anotherParameter, DataTable dt) 
{ 
    SqlDataAdapter adapter = new SqlDataAdapter("SPName", Connection.Connect); 
    adapter.SelectCommand.CommandType = CommandType.StoredProcedure; 
    adapter.SelectCommand.Parameters.Add("@command",SqlDbType.NVarChar).Value=command; 

    //another one without @   
    adapter.SelectCommand.Parameters.Add("anotherParameter",SqlDbType.NVarChar).Value=anotherParameter; 
    try 
     { 

      return adapter.Fill(dt); 
     } 
    catch (Exception ex) 
     { 
      return -1; 
     } 
     finally 
     { 
      adapter.Dispose(); 
     }  

} 

這有時會運行和失敗的另一個會發生什麼?

感謝

+3

你試過這段代碼嗎?你有什麼錯誤 – 2013-04-22 09:16:20

+1

@Mido相當肯定我們有一些代碼指定'@',有些則不指定。兩者都有效。 – 2013-04-22 09:17:59

+0

@Garath好吧,我試過了,但我注意到它有時候有時候並且有時候不起作用。 – Mido 2013-04-22 09:19:44

回答