locked
for loop in sqlcommand? RRS feed

  • Question

  • User1748199839 posted

    I have to pass more than 10paramters to my stored procedure.Is there a way of using any loop

    to do so or I have to write the command syntax for each parameter seperatly?

    This is what I have written so far:-

    SqlParameter para = new SqlParameter();

    para.ParameterName = "@firstname";
    para.DbType = DbType.String;
    para.Value = firstname;

    para.ParameterName = "@lastname";
    para.DbType=DbType.String;
    para.Value = lastname;
    
    
    I have more than 10 parameters to write for.Is there a quick and easy way to write?
    Friday, December 30, 2011 2:38 AM

Answers

  • User197322208 posted

    para.ParameterName = "@lastname";

    I have to write the command syntax for each parameter seperatly

    Yes. Take your time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2011 2:48 AM
  • User3866881 posted

    I have to pass more than 10paramters to my stored procedure.Is there a way of using any loop

    Hello:)

    If your stored procdure is something like @param1,@param2,……,@param10。You can do that——

    for(int i=1;i<=10;++i)
    {
       SqlCommand.Parameters.AddWithValue("@param"+i,"Your Value"+i);

    ………………

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 31, 2011 8:38 PM

All replies

  • User197322208 posted

    para.ParameterName = "@lastname";

    I have to write the command syntax for each parameter seperatly

    Yes. Take your time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2011 2:48 AM
  • User3866881 posted

    I have to pass more than 10paramters to my stored procedure.Is there a way of using any loop

    Hello:)

    If your stored procdure is something like @param1,@param2,……,@param10。You can do that——

    for(int i=1;i<=10;++i)
    {
       SqlCommand.Parameters.AddWithValue("@param"+i,"Your Value"+i);

    ………………

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 31, 2011 8:38 PM