2011-01-20 31 views

回答

3

如何嘗試使用SqlCommandBuilder.DeriveParameters來填充參數集合?

用法:

// Create Command 
SqlCommand command = connection.CreateCommand(); 
command.CommandType = CommandType.StoredProcedure; 
command.CommandText = storedProcedureName; 

// Open Connection 
connection.Open(); 

// Discover Parameters for Stored Procedure and populate command.Parameters Collection. 
// Causes Rountrip to Database. 
SqlCommandBuilder.DeriveParameters(command); 

你顯然需要再填充值,每個參數。

+0

非常感謝! – idm 2011-01-20 12:01:56

0

AFAIK,你不能傳遞一個沒有參數名的參數。但是,如果您使用企業庫數據訪問應用程序塊,你可以做這樣的事情:

 Database db = DatabaseFactory.CreateDatabase("DatabaseName"); 
     DbCommand cmd = new SqlCommand("SP Name Here"); 
     cmd.CommandType = CommandType.StoredProcedure; 
     db.DiscoverParameters(cmd); 

現在你的Command對象將包含所有的參數信息。

相關問題