none
SqlCommand.Parameters.GetEnumurator RRS feed

  • Question

  •  

    Hi all,

             I am trying to print parameter value in Sqlcommand.Parameter.But this not printing . I am getting error "numeration has either not started or has already finished"

     

    Code Snippet

    SqlParameter[] sp =new SqlParameter[2];

    sp[0] = new SqlParameter();

    sp[0].ParameterName = "@CategoryID";

    sp[0].Value = 1;

    sp[1] = new SqlParameter();

    sp[1].ParameterName = "@CategoryName";

    sp[1].Value = "Beverages";

    sqlcmd.Parameters.AddRange(sp);

     

    IEnumerator spc;

    SqlParameter p;

    spc = sqlcmd.Parameters.GetEnumerator();

    do

    {

    p = (SqlParameter)spc.Current;

    } while (spc.MoveNext());

     

     

    What  I am doing wrong Here ?

     

    Dana

    Friday, February 8, 2008 10:24 AM

Answers

  • Hello,

    First it is not the good forum, you should use this one.

    With an IEnumerator, you must start with MoveNext.

    So in your case, you need to do this:

    Code Snippet

    while (spc.MoveNext())

    {

      p = (SqlParameter)spc.Current;

    }

     

     

    Imagine that you haven't elements on your Enumerator, you will have a problem with your code.

     

     

    Friday, February 8, 2008 1:02 PM

All replies

  • Hello,

    First it is not the good forum, you should use this one.

    With an IEnumerator, you must start with MoveNext.

    So in your case, you need to do this:

    Code Snippet

    while (spc.MoveNext())

    {

      p = (SqlParameter)spc.Current;

    }

     

     

    Imagine that you haven't elements on your Enumerator, you will have a problem with your code.

     

     

    Friday, February 8, 2008 1:02 PM
  • Thank you MatthieuMEZIL

     

    Saturday, February 9, 2008 6:17 AM