c# - Execute Stored Procedure With Nameless Parameters -


I was thinking that there is a way to execute a stored procedure with the naming of parameters. Which means that C # resolves the parameter in order, which is declared within the stored procedure.

  Public stable datatable GetRelatedResources (string stored procedure, object [] parameter) {var result = new datatile (); Use {SqlConnection conn = new SqlConnection ()) ({SqlCommand cmd = new SqlCommand (ConfigurationManager.ConnectionStrings ["MK3Entities"]. ConnectionString)) {conn.Open (); Cmd.Connection = conn; Cmd.CommandType = CommandType.StoredProcedure; Cmd.CommandText = Archived Processes; If (parameter! = Null) {foreach (var param in paragraph parameter) {// I want to do something like this CMD Parameter. AddWithValue (Ultimate); }} SqlDataAdapter Adapter = New SqlDataAdapter (CMD); Adapter.Fill (result); }}} Hold (ex before) {MMSLogger.Instance.WriteToLog ("Exceptions stored procedure:" pre-message); } Return results; }  

Execute an command , and parameter Pass in '@ P1', '@ P2' etc.:

  cmd.CommandType = CommandType.Text; Cmd.CommandText = 'exec' + Archived Process; Int i = 0; String comma = ''; Foreign (multiple paras in paramet) {var paramName = String.Format ("@P {0}", i); Cmd.CommandText + = Comma + surname; Cmd.Parameters.AddWithValue (nickname, ultimate); ++ i; Comma = ','; }  

Keep in mind that AddwithValue is a huge demonstration antipattern.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -