2013-04-22 163 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

回答