有沒有辦法從SqlCommand
獲取參數集合時CommandType = Text?SqlCommand(CommandType文本)檢索參數集合
例如:
string MyDinamicSql = @"SELECT * FROM USERS where USERName = @Param1 and [email protected]";
SqlCommand comand = connection.CreateCommand();
comand.CommandText = MyDinamicSql;
comand.CommandType = System.Data.CommandType.Text;
//Do something for fill comand.Parameters from MyDinamicSql...
我想辦法讓一個參數採集與[@參數1,@參數2] ...我不知道SQL查詢(它們是動態的),我想獲取我的應用程序的參數,將它們創建爲輸入控件。
我不能這樣做與SqlCommandBuilder.DeriveParameters(command)
,因爲它只適用於存儲過程。
謝謝!
如何生成SQL字符串?它們是從代碼構建還是來自用戶? – 2012-01-27 18:43:08
他們被寫入沒有地方參數名稱的商店...: - /他們來自用戶,我的應用程序不知道查詢參數。 – 2012-01-27 18:55:41
在delphi中,當它的引擎解析sql時,我有類似FetchParams(在ClientDataSet上)並執行此操作。但在C#中我沒有發現任何喜歡它。 – 2012-01-27 19:07:54