Guest User

Untitled

a guest
May 2nd, 2012
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Is there a way to check if a parameter is in stored procedure?
  2. ArrayList pars = new ArrayList();
  3. SqlParameter p;
  4. int tryInt;
  5. for (int i = 0; i < req.QueryString.Count; i++)
  6. {
  7. key = req.QueryString.AllKeys[i];
  8.  
  9. if (int.TryParse(req[key], out tryInt))
  10. {
  11. p = new SqlParameter("@" + key, SqlDbType.Int);
  12. p.Value = tryInt;
  13. pars.Add(p);
  14. }
  15. }
  16.  
  17. @someParameter is not a parameter for procedure some_sproc
  18.  
  19. if (paramExists("@" + key, "some_sproc") && int.TryParse(req[key], out tryInt))
  20. {
  21. p = new SqlParameter("@" + key, SqlDbType.Int);
  22. p.Value = tryInt;
  23. pars.Add(p);
  24. }
  25.  
  26. SELECT parameter_name, ordinal_position FROM INFORMATION_SCHEMA.parameters
  27. WHERE SPECIFIC_NAME = 'some_sproc'
  28.  
  29. using (SqlConnection sqlConn = new SqlConnection(yourConnStr))
  30. using (SqlCommand sqlCmd = new SqlCommand(yourProcedureName, sqlConn))
  31. {
  32. sqlConn.Open();
  33. sqlCmd.CommandType = CommandType.StoredProcedure;
  34. SqlCommandBuilder.DeriveParameters(sqlCmd);
  35. // now you can check parameters in sqlCmd.Parameters
  36. }
Advertisement
Add Comment
Please, Sign In to add comment