Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is there a way to check if a parameter is in stored procedure?
- ArrayList pars = new ArrayList();
- SqlParameter p;
- int tryInt;
- for (int i = 0; i < req.QueryString.Count; i++)
- {
- key = req.QueryString.AllKeys[i];
- if (int.TryParse(req[key], out tryInt))
- {
- p = new SqlParameter("@" + key, SqlDbType.Int);
- p.Value = tryInt;
- pars.Add(p);
- }
- }
- @someParameter is not a parameter for procedure some_sproc
- if (paramExists("@" + key, "some_sproc") && int.TryParse(req[key], out tryInt))
- {
- p = new SqlParameter("@" + key, SqlDbType.Int);
- p.Value = tryInt;
- pars.Add(p);
- }
- SELECT parameter_name, ordinal_position FROM INFORMATION_SCHEMA.parameters
- WHERE SPECIFIC_NAME = 'some_sproc'
- using (SqlConnection sqlConn = new SqlConnection(yourConnStr))
- using (SqlCommand sqlCmd = new SqlCommand(yourProcedureName, sqlConn))
- {
- sqlConn.Open();
- sqlCmd.CommandType = CommandType.StoredProcedure;
- SqlCommandBuilder.DeriveParameters(sqlCmd);
- // now you can check parameters in sqlCmd.Parameters
- }
Advertisement
Add Comment
Please, Sign In to add comment